Microsoft安全更新MS13-004后在MSTest中执行单元测试时,System.InvalidProgramException [英] System.InvalidProgramException when executing unit tests in MSTest after Microsoft Security update MS13-004

查看:110
本文介绍了Microsoft安全更新MS13-004后在MSTest中执行单元测试时,System.InvalidProgramException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2013年1月8日应用Microsoft安全更新后 http ://technet.microsoft.com/zh-cn/security/bulletin/ms13-004 我们已经开始在构建服务器上以及本地开发箱上运行测试时,体验到CI构建在构建服务器上以及本地的失败.

After applying the Microsoft Security update on the 8th of January 2013 http://technet.microsoft.com/en-us/security/bulletin/ms13-004 we have started to experience failures in our CI builds on our build servers and locally when running tests on our development boxes.

我们收到 System.InvalidProgramException:公共语言运行时检测到无效程序.

这仅在使用MSTest运行使用Castle Windsor DynamicProxy的测试时发生,尽管我不认为DynamicProxy在这里有问题.

This only happens when running tests using MSTest that make use of Castle Windsor DynamicProxy although I am not convinced DynamicProxy is at fault here.

下面将生成示例的示例代码.

An example piece of code that would generate the exception is below.

    [TestMethod]
    public void ShouldBeAbleToGenerateADynamicProxyForAnObject()
    {
        var container = new WindsorContainer();

        container.Register(Component.For<TestInterceptor>());

        container.Register(Component.For<ISomething>()
                               .Instance(new TestDependency("Called from test framework."))
                               .LifeStyle.Transient);

        container.Register(Component.For<IService>()
                               .ImplementedBy<TestService>()
                               .Interceptors(InterceptorReference.ForType<TestInterceptor>())
                               .Anywhere
                               .LifeStyle.Transient);

        var service = container.Resolve<IService>();
        Assert.AreEqual("Called from test framework.", service.MethodNumberOne());
    }    

这将生成一个堆栈跟踪,最终在调用DynamicProxy中的MixinData构造函数时引发异常:

This generates a stack trace that ends up with the exception being thrown when invoking the MixinData constructor in DynamicProxy:

Castle.DynamicProxy.MixinData..ctor(IEnumerable`1 mixinInstances) Castle.DynamicProxy.ProxyGenerationOptions.Initialize() Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(类型proxyTargetType,类型[]接口,ProxyGenerationOptions选项) Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy,Type [] AdditionalInterfacesToProxy,type targetType,ProxyGenerationOptions选项) Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy,Type [] AdditionalInterfacesToProxy,type targetType,ProxyGenerationOptions选项) Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type interfaceToProxy,Type [] AdditionalInterfacesToProxy,对象目标,ProxyGenerationOptions选项,IInterceptor []拦截器) Castle.Windsor.Proxy.DefaultProxyFactory.Create(IKernel内核,对象目标,ComponentModel模型,CreationContext上下文,Object []构造函数自变量) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext上下文,ConstructorCandidate构造函数,Object []参数) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext上下文,ConstructorCandidate构造函数,Object []参数) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext上下文) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext上下文) Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext上下文,负担) Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext上下文,布尔值在外部跟踪) Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext上下文,IReleasePolicy releasePolicy) Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext上下文,布尔值requireDecommission,布尔值instanceRequired,负担和负担) Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext上下文,Boolean instanceRequired) Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext上下文) Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler处理程序,类型服务,IDictionary AdditionalArguments,IReleasePolicy策略) Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(类型服务,IDictionary自变量,IReleasePolicy策略) Castle.MicroKernel.DefaultKernel.Resolve(类型服务,IDictionary自变量) Castle.Windsor.WindsorContainer.ResolveT TestCastleWindsorDynamicProxy.cs中的ShouldBeAbleToGenerateADynamicProxyForAnObject():第34行

Castle.DynamicProxy.MixinData..ctor(IEnumerable`1 mixinInstances) Castle.DynamicProxy.ProxyGenerationOptions.Initialize() Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options) Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, Type targetType, ProxyGenerationOptions options) Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, Type targetType, ProxyGenerationOptions options) Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, Object target, ProxyGenerationOptions options, IInterceptor[] interceptors) Castle.Windsor.Proxy.DefaultProxyFactory.Create(IKernel kernel, Object target, ComponentModel model, CreationContext context, Object[] constructorArguments) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context) Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) Castle.Windsor.WindsorContainer.ResolveT ShouldBeAbleToGenerateADynamicProxyForAnObject() in TestCastleWindsorDynamicProxy.cs: line 34

我的第一个想法是,在创建代理时,DynamicProxy实际上在安全更新后生成了无效的IL,但据我所知并非如此,因为它没有走得那么远.我对Castle进行了反编译,并逐步通过调试器进行调试,当通过以下调用从ProxyGenerationOptions类调用MixinData构造函数时,我看到按照堆栈跟踪抛出异常(注意:在上面的代码示例中. mixins将为null,但这是预期的,并且可以在调用构造函数的代码中正确处理):

My first thought was that DynamicProxy was actually generating invalid IL after the security update when creating the Proxy but as far as I can see this is not the case as it is not getting that far. I decompiled Castle and stepped through with the debugger and I see the exception being thrown as per the stack trace, when the MixinData constructor is called from the ProxyGenerationOptions class via a call as below (Note: in the code example above this.mixins will be null but this is expected and handled correctly in the code of the constructor being called):

this.mixinData = new Castle.DynamicProxy.MixinData(this.mixins);

除了MSTest运行程序之外,所有其他功能均按预期运行,我们的应用程序继续运行,并且在使用MSTest的xUnit或什至TestDriven.NET中运行单元测试时,它们不会生成异常.我们只看到这种行为在Visual Studio中运行测试,或者在自动构建中使用TFS和MSBuild脚本.

Outside of the MSTest runner everything works as expected, our applications continue to function and when running the unit tests in xUnit or even TestDriven.NET using MSTest they do not generate the exception. We only see this behaviour running tests from Visual Studio or using TFS and our MSBuild scripts for our automated builds.

在向微软索取支持票之前,我想我们会问其他人是否经历过类似的事情或对导致问题的原因有任何想法吗?

Before we raise a support ticket with Microsoft I thought we would ask if anyone else has experienced anything similar or has any ideas about what may be causing our issue?

在今天早上经历了几件事之后,我们发现这实际上与我们正在使用的Castle NuGet软件包有关.当我们使用最新的NuGet包引用Castle时,最终引用的是为 .NET Client Profile 4 编译的Castle.Core程序集.尚未完全确定).将引用更改为为.NET 3.5编译的版本,可以确保测试在所有情况下都能按预期通过.

After going through a few new things this morning we have discovered that this actually seems to relate to the Castle NuGet package we are using. When we reference Castle using the latest NuGet package we end up having a reference to the Castle.Core assembly compiled for the .NET Client Profile 4 this reference is the cause of the exception above (Why? I am not entirely sure yet). Changing the reference to the version compiled for .NET 3.5 ensures the tests pass as expected in all scenarios.

经过更多的挖掘之后,似乎确实存在一个关联的问题(这使我们有理由回到Microsoft并了解他们的意见).

After some more digging there does appear to be a linked issue (which has given us grounds to go back to Microsoft and see what they have to say) Common Language Runtime detected an invalid program error in unit testing

推荐答案

尝试运行使用TypeMock的测试时,我遇到了类似的错误.为了解决该问题,我在Visual Studio中打开了解决方案,然后选择了 Test - Edit Test Settings .在测试设置对话框中,选择主机并将其切换为在64位计算机上以64位进程运行测试.

I had a similar error, when trying to run tests which used TypeMock. In order to solve the problem I opened up my solution in Visual Studio and selected Test - Edit Test Settings. In the Test Settings dialog I selected Hosts and switched it to Run tests in 64 bit process on 64 bit machine.

让我知道这是否有帮助.如果这与您的错误无关,请通知我们,我将删除答案.

Let me know if this helps. If this has nothing to do with your error, let me know and I'll remove my answer.

这篇关于Microsoft安全更新MS13-004后在MSTest中执行单元测试时,System.InvalidProgramException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆