C# &引用;vshost32.exe已停止工作“;或;致命的执行引擎错误“;在VisualStudio中
我在VisualStudio中遇到一些奇怪的错误,找不到正确的方向。我正在用C#编写一些后端,它与第三方API联系以检索数据。所讨论的代码是单个类,是更大解决方案的一部分,但必须是问题所在,因为不使用此类时不会出现错误 计算机设置:C# &引用;vshost32.exe已停止工作“;或;致命的执行引擎错误“;在VisualStudio中,c#,exception,visual-studio-2013,crash,httpwebrequest,C#,Exception,Visual Studio 2013,Crash,Httpwebrequest,我在VisualStudio中遇到一些奇怪的错误,找不到正确的方向。我正在用C#编写一些后端,它与第三方API联系以检索数据。所讨论的代码是单个类,是更大解决方案的一部分,但必须是问题所在,因为不使用此类时不会出现错误 计算机设置: Visual Studio 2013,更新4 Windows 10,预览版本10041 遇到错误 昨天,应用程序在调试时开始表现出奇怪的行为。 第一个错误我记不清了,但大致上是“坏的”或“损坏的内存” 在不改变程序的情况下,我还可能遇到FatalExecut
- Visual Studio 2013,更新4
- Windows 10,预览版本10041
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Specialized;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace whatsfordinner {
public class eTilbudRetriever {
//Web method names
readonly String Get = "GET";
readonly String Post = "POST";
readonly String Update = "UPDATE";
readonly String Delete = "DELETE";
//Parameter identifiers
readonly String ParamApiKey = "api_key";
readonly String ParamLatitude = "r_lat";
readonly String ParamLongitude = "r_lng";
readonly String ParamRadius = "r_radius";
readonly String ParamLimit = "limit";
readonly String ParamOffset = "offset";
//Parameter values
String Latitude = "57.051188"; //Aalborg coordinates
String Longitude = "9.922371";
String Radius = "800000"; //Radius in meters (800km)
String Limit = "48"; // Results per query
//Custom header identifiers
readonly String HeaderXToken = "X-Token";
readonly String HeaderXSignature = "X-Signature";
//Custom header values
readonly String ContentType = "application/json";
//Web Addresses
readonly String HostAddress = "https://api.etilbudsavis.dk/v2/";
readonly String Sessions = "sessions";
readonly String Stores = "stores";
readonly String Offers = "offers";
readonly String Dealers = "dealers";
//Keys
readonly String ApiKey = "<Redacted>";
readonly String ApiSecret = "<Redacted>";
String XToken; //Same as a Session Token in documentation
String XSignature; //Same as a Session Signature in documentation
public eTilbudRetriever() {
//Create a body consisting of the API key
List<KeyValuePair<String, String>> body = new List<KeyValuePair<String, String>>();
body.Add(new KeyValuePair<String, String>(ParamApiKey, ApiKey));
//Send request to create a new session
String response = SendWebRequest(Post, Sessions, body);
//Get the Session Token from the response
dynamic json = JObject.Parse(response);
XToken = json.token;
//Save the Session Signature as well (SHA256 version of API Secret combined with Session Token)
XSignature = ConvertToSha256(ApiSecret + XToken);
}
public void GetDealersList() {
GetList(Dealers);
}
public void GetStoresList() {
GetList(Stores);
}
public void GetOffersList() {
GetList(Offers);
}
private void GetList(string target) {
List<String> resultSet = new List<String>();
String result;
int offset = 0;
//Add desired parameters as headers for the eTilbudsavisen API
List<KeyValuePair<String, String>> query = new List<KeyValuePair<String, String>>();
query.Add(new KeyValuePair<String, String>(ParamLatitude, Latitude));
query.Add(new KeyValuePair<String, String>(ParamLongitude, Longitude));
query.Add(new KeyValuePair<String, String>(ParamRadius, Radius));
query.Add(new KeyValuePair<String, String>(ParamLimit, Limit));
query.Add(new KeyValuePair<String, String>(ParamOffset, offset.ToString()));
//Retrieve a result through the request
result = SendWebRequest(Get, target, query);
/*
* If result is valid, add it to the set of valid results.
* Keep sending requests and increase the offset to avoid duplicated results
* Stop when returned results are no longer valid
*/
while (!String.IsNullOrEmpty(result)) {
resultSet.Add(result);
offset += Int32.Parse(Limit);
query[query.Count-1] = new KeyValuePair<String, String>(ParamOffset, offset.ToString());
result = SendWebRequest(Get, target, query);
}
}
private String SendWebRequest(String method, String extension, List<KeyValuePair<String, String>> arguments) {
try {
String finalAddress = HostAddress + extension;
//Add query to Address (if applicable)
if (method.Equals(Get)) {
finalAddress += '?';
finalAddress += arguments[0].Key + '=' + arguments[0].Value;
for (int i = 1; i < arguments.Count; i++) {
finalAddress += '&' + arguments[i].Key + '=' + arguments[i].Value;
}
}
//Create request and set mandatory header properties
var request = (HttpWebRequest)WebRequest.Create(finalAddress);
request.Method = method;
request.ContentType = ContentType;
request.Accept = ContentType;
//If a Session Token and Signature are available (= After session create), add as headers
if (!String.IsNullOrEmpty(XToken)) {
request.Headers.Add(HeaderXToken, XToken);
request.Headers.Add(HeaderXSignature, XSignature);
}
//Create JSON string containing the desired body arguments (if applicable)
if (method.Equals(Post)) {
//Write body to API
using (var writer = new StreamWriter(request.GetRequestStream())) {
writer.Write(MakeJsonBody(arguments));
}
}
//get response as a JSON object in string format
var response = (HttpWebResponse)request.GetResponse();
return new StreamReader(response.GetResponseStream()).ReadToEnd();
} catch (UriFormatException e) {
Console.WriteLine(e.ToString());
return null;
} catch (WebException e) {
Console.WriteLine(e.ToString());
return null;
}
}
private String ConvertToSha256(String text) {
byte[] bytes = Encoding.UTF8.GetBytes(text);
SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
string hashString = string.Empty;
foreach (byte x in hash) {
hashString += String.Format("{0:x2}", x);
}
return hashString;
}
private String MakeJsonBody(List<KeyValuePair<String, String>> arguments) {
String json = "{";
foreach (KeyValuePair<String, String> kv in arguments) {
json += "\"" + kv.Key + "\": \"" + kv.Value + "\"";
if (arguments.IndexOf(kv) != arguments.Count() - 1) {
json += ", ";
}
}
json += "}";
return json;
}
}
Windows 10,预览版本10041
这是您的程序如此崩溃的唯一可能原因。没有其他原因,您的代码没有做任何危险的事情,并且Newtonsoft.Json已被数百万程序以各种可能的方式猛烈抨击。您正在使用.NET Framework(v4.6)的测试版以及操作系统。感谢所有Microsoft客户帮助调试此新软件,您的问题不是我们必须解决的问题。希望FEEE崩溃非常严重,难以调试
您应该做的是向Microsoft提交崩溃进程的小型转储文件,以便他们能够修复潜在的错误。不管是什么,您的问题中没有任何线索。可能是对x64抖动(项目代码名RyuJit)的完全重写。现在它没有bug的可能性很小,这样的bug肯定会像这样使你的程序崩溃。不过这只是一个猜测
微软免费提供这些预览。他们的基本意图是在产品发布之前将漏洞清除。应该在夏天左右发生。只有这样,他们才能有信心,一旦产品发布,他们的支持电话线不会过载。测试版更新来得很快,而且很快就会更新ous,.NET 4.6有6个CTP版本。这是前所未有的,通常不超过3个。至少有一部分是VS2015的测试版,该版本中有很多新内容。你没有使用,这也没有帮助
你在这里的角色是一个无偿的测试人员。这与你的另一个角色,一个以编写和调试代码为生的程序员是不相容的。你的代码,而不是其他人的。当你不能像这样陷入困境时,唯一明智的做法就是取消该测试程序的订阅。恢复你的代码这台机器的框架和操作系统的已知良好版本。现在是.NET4.5.2和Windows8.1
Windows 10,预览版本10041
这是您的程序如此崩溃的唯一可能原因。没有其他原因,您的代码没有做任何危险的事情,并且Newtonsoft.Json已被数百万程序以各种可能的方式猛烈抨击。您正在使用.NET Framework(v4.6)的测试版以及操作系统。感谢所有Microsoft客户帮助调试此新软件,您的问题不是我们必须解决的问题。希望FEEE崩溃非常严重,难以调试
您应该做的是向Microsoft提交崩溃进程的小型转储文件,以便他们能够修复潜在的错误。不管是什么,您的问题中没有任何线索。可能是对x64抖动(项目代码名RyuJit)的完全重写。现在它没有bug的可能性很小,这样的bug肯定会像这样使你的程序崩溃。不过这只是一个猜测
微软免费提供这些预览。他们的基本意图是在产品发布之前将漏洞清除。应该在夏天左右进行。唯一的真正方法是他们可以有信心他们的支持电话线不会接通
eTilbudRetriever retriever = new eTilbudRetriever();
retriever.GetDealersList();