Container.Verify 有时会抛出 System.ExecutionEngineException
Container.Verify throws System.ExecutionEngineException sometimes
此问题仅发生在本地,发生在 IISExpress 中基于 WCF 的 Web api 项目 运行 上。
它相当随机地发生。
"An unhandled exception of type 'System.ExecutionEngineException' occurred in SimpleInjector.dll"
当我执行 container.Verify()
时会发生这种情况
任何可能导致此问题的想法,或者如何调试它?
ExecutionEngineException
通常是由分析工具引起的,例如:
- 微软 IntelliTrace
- JetBrains dotTrace
但我发现这也是由 Microsoft 的测试运行器 (MSTest) 引起的。
这些工具的局限性(或缺陷)导致它们无法应对动态汇编编译。动态汇编编译是Simple Injector用来优化性能的。
处理此问题的最有效方法(无需对您使用的分析或测试工具进行任何更改)是禁用 Simple Injector 的动态汇编编译,如下所示:
container.Options.EnableDynamicAssemblyCompilation = false;
这意味着 Simple Injector 将编译的委托将使用轻量级代码生成(速度稍慢,但无需担心)创建,而不是创建新的内存中程序集。
另一种选择是禁用 IntelliTrace 或 dotTrace 等工具,但这当然并不总是一个选项。对于 MSTest,您还可以禁用其 'Keep Test Execution Engine Running' 功能。
Side note: There's an old issue on the old Codeplex site that describes the problem and the solution. Unfortunately, due to many mistakes by the Codeplex team, this issue can't be found by Googling, and the issue has become unreadable over time.
此问题仅发生在本地,发生在 IISExpress 中基于 WCF 的 Web api 项目 运行 上。 它相当随机地发生。
"An unhandled exception of type 'System.ExecutionEngineException' occurred in SimpleInjector.dll"
当我执行 container.Verify()
时会发生这种情况任何可能导致此问题的想法,或者如何调试它?
ExecutionEngineException
通常是由分析工具引起的,例如:
- 微软 IntelliTrace
- JetBrains dotTrace
但我发现这也是由 Microsoft 的测试运行器 (MSTest) 引起的。
这些工具的局限性(或缺陷)导致它们无法应对动态汇编编译。动态汇编编译是Simple Injector用来优化性能的。
处理此问题的最有效方法(无需对您使用的分析或测试工具进行任何更改)是禁用 Simple Injector 的动态汇编编译,如下所示:
container.Options.EnableDynamicAssemblyCompilation = false;
这意味着 Simple Injector 将编译的委托将使用轻量级代码生成(速度稍慢,但无需担心)创建,而不是创建新的内存中程序集。
另一种选择是禁用 IntelliTrace 或 dotTrace 等工具,但这当然并不总是一个选项。对于 MSTest,您还可以禁用其 'Keep Test Execution Engine Running' 功能。
Side note: There's an old issue on the old Codeplex site that describes the problem and the solution. Unfortunately, due to many mistakes by the Codeplex team, this issue can't be found by Googling, and the issue has become unreadable over time.