[英]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). SpecFlow将在FeatureSetup方法中引发System.Reflection.ReflectionTypeLoadException,其中它不提供有关异常的任何信息,并会要求您检索LoaderExceptions属性(如下所示的错误)。 Setting a Debugging break at the beginning of the generated FeatureSetup method to look at the problem would not trigger the break.
在生成的FeatureSetup方法的开头设置调试中断以查看问题不会触发中断。 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.
检索LoaderExceptions属性以获取更多信息。
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. 在生成的FeatureSetup方法中的所有代码周围添加一个try / catch块,并添加Console.WriteLine以输出每个LoaderException,如下所示。 The LoaderException Message(s) will then be displayed on your NUnit GUI screen when you run the test.
然后,当您运行测试时,LoaderException消息将显示在NUnit GUI屏幕上。 StackFlow link How to retrieve the LoaderException property?
StackFlow链接如何检索LoaderException属性? 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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.