简体   繁体   中英

SpecFlow FeatureSetup throws System.Reflection.ReflectionTypeLoadException

SpecFlow will throw a System.Reflection.ReflectionTypeLoadException in the FeatureSetup method where it does not provide any information about the exception and will ask you to retrieve the LoaderExceptions property (error shown below). Setting a Debugging break at the beginning of the generated FeatureSetup method to look at the problem would not trigger the break. How can I find out the source of this problem?

Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Add a try/catch block around all of the code in the generated FeatureSetup method and add Console.WriteLine to output each LoaderException as shown below. The LoaderException Message(s) will then be displayed on your NUnit GUI screen when you run the test. StackFlow link How to retrieve the LoaderException property? was very helpful.

        try
        {
            testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
            TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "MyTest", null, ProgrammingLanguage.CSharp, ((string[])(null)));
            testRunner.OnFeatureStart(featureInfo);
        }
        catch (Exception e)
        {
            var typeLoadException = e as ReflectionTypeLoadException;
            var loaderExceptions = typeLoadException.LoaderExceptions;
            foreach (Exception le in loaderExceptions)
                Console.WriteLine("LoaderException Msg = {0}", le.Message);
        }

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