简体   繁体   中英

“vshost32.exe has stopped working” OR “fatal execution engine error” in Visual Studio

I'm encountering some odd errors in Visual Studio and can't find head or tail. I'm coding some backend in C# which contacts a third party API to retrieve data. The code in question, a single class, is part of a larger solution, but must be the problem as the errors encountered does not occur when not using this class.

Computer setup:

  • Visual Studio 2013, update 4

  • Windows 10, Preview Build 10041

Errors encountered

Yesterday the application started behaving weird when debugging it. The first error I don't remember exactly, but it was something along the lines of "bad" or "corrupted memory".

Without altering the program, I could also encounter a FatalExecutionEngineError exception, which would be thrown immediately after trying to run the program (It didn't make it to the first breakpoint, which was on the first line in the Main entry of the program. Weird!

EDIT: Looks like this:

Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'PathRedacted\\whatsfordinner\\whatsfordinner\\bin\\Debug\\whatsfordinner.vshost.exe'.

Additional information: The runtime has encountered a fatal error. The address of the error was at 0x613e4379, on thread 0x11ac. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

In the end I rebooted my computer since it was all very strange. Problem solved until today.

Now I can't seem to run the program at all; Upon running the program, vshost32.exe just crashes. I don't get any error messages or anything to hint at where the issue is.

Troubleshooting steps

  1. Rebooted my computer - No change, vshost32.exe crashes upon execution
  2. Outcommented the two lines where the class in question was used - Program runs fine.
  3. Tried starting the program as "Release" rather than "Debug". - Program seems to run fine, although I can't test it to the end. (The class is not entirely done yet, and I don't want to spam the API in question)
  4. Tried running the program on another computer running Windows 7 and Visual Studio 2012. - Program seemed to run fine.

At this point I'm pretty lost. I have little idea as to where the issue might be. The source code unfortunately consists of nearly 200 lines, but as I have no clue, I am posting it all.

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;
    }
}

}

In Main , this is what is executed in relation to the class. The program runs fine when removing these lines from the solution.

eTilbudRetriever retriever = new eTilbudRetriever();
retriever.GetDealersList();

Windows 10, Preview Build 10041

That's the only cue to the possible reason why your program is crashing like this. There are no other ones, your code doesn't do anything dangerous and Newtonsoft.Json has been slammed every possible way by millions of programs. You are using beta versions of both the .NET Framework (v4.6) and the operating system. Thanks on behalf of all Microsoft customers to help debug this new software, your problem is not one that we'll have to troubleshoot. Hopefully, FEEE crashes are exceedingly nasty and hard to debug.

What you are supposed to do is submit a minidump of the crashed process to Microsoft so they can fix the underlying bug. Whatever it might be, there are no cues in your question. Maybe it is the complete rewrite of the x64 jitter (project code name RyuJit). The odds that it has no bugs right now are very slim and such a bug can certainly crash your program like this. That's just a wild guess though.

Microsoft makes these previews available at no cost. Their underlying intention is to get the bugs out before the product ships. Should happen somewhere around the summer. Only real way they can have some confidence that their Support phone lines are not going to get overloaded once they ship the product. The beta updates come fast and furious, there have been 6 CTP versions of .NET 4.6. Quite unprecedented, there usually are no more than 3. At least part of it is the beta for VS2015, lots and lots of new stuff in that release. Which you are not using, that doesn't help either.

Your role in this is one as an unpaid beta-tester. This tends to be rather incompatible with your other role, a programmer that makes a living writing and debugging code. Your code, not somebody else's. When you can't afford to be bogged-down like this then the only sensible thing to do is to unsubscribe from that beta program. Restore your machine to a known-good version of the framework and the operating system. Right now that's .NET 4.5.2 and Windows 8.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM