小编Ale*_*lex的帖子

System.InvalidProgramException在Microsoft安全更新MS13-004之后在MSTest中执行单元测试时

在2013年1月8日应用Microsoft安全更新http://technet.microsoft.com/en-us/security/bulletin/ms13-004后,我们已经开始在我们的构建服务器和本地的CI构建中遇到故障在我们的开发盒上运行测试.

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

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

下面将生成一个生成异常的示例代码.

    [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());
    }    
Run Code Online (Sandbox Code Playgroud)

这会生成一个堆栈跟踪,最终会在DynamicProxy中调用MixinData构造函数时抛出异常:

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,对象目标,ProxyGenerationOptions选项,IInterceptor []拦截器)Castle.Windsor.Proxy.DefaultProxyFactory.Create(的iKernel内核,对象目标,ComponentModel模型,CreationContext上下文中,对象[],构造函数)Castle.M icroKernel.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 …

c# mstest castle-windsor castle-dynamicproxy nuget-package

6
推荐指数
1
解决办法
2879
查看次数