2

我正在从 2.5.1 版升级到 3.1.0 版,而过去的工作不再适用。我正在尝试解决一个创建使用泛型的组件的工厂。抛出的错误是“ComponentActivator:无法代理”,其中无法解析的工厂名称

public class MyObject { }

public class MyContext { }

public class DummyComponent<T> : IDummyComponent<T> where T : MyObject { }

public interface IDummyComponent<T> { }

public interface IDummyComponentFactory
{
    IDummyComponent<T> Create<T>(object o);
}

class Program
{
    static void Main(string[] args)
    {
        var windsorContainer = new WindsorContainer();
        windsorContainer.AddFacility<TypedFactoryFacility>()
            .Register(
                Component.For(typeof(IDummyComponent<>)).ImplementedBy(typeof(DummyComponent<>)),
                Component.For<IDummyComponentFactory>().AsFactory());
        var factory = windsorContainer.Resolve<IDummyComponentFactory>(); <-- Error Occurs Here
        var myDummyComponent = factory.Create<MyObject>(new object());
    }
}

此代码在 Entity Framework 存储库中以下列方式使用,用于将 EntityContext 传递到另一个存储库,以便像这样处理已删除的对象:

    public virtual IEnumerable<T> Where(Expression<Func<T, bool>> predicate, bool showDeleted = false, MergeOption mergeOption = MergeOption.AppendOnly)
    {           
        if (typeof(IDeletable).IsAssignableFrom(typeof(T)))
        {
            var factory = Container.Instance.Resolve<IDeletableRepositoryFactory>();
            var repository = factory.GetDeletableRepository<T>(EntityContext);
            return repository.Where(predicate, showDeleted, mergeOption);
        }

        return GetObjectSet(mergeOption).Where(predicate);                      
    }

更新:包括内部异常

System.Security.VerificationException
{"Operation could destabilize the runtime."} at
Castle.MicroKernel.Proxy.ProxyOptions.get_MixIns() in 
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\Proxy\ProxyOptions.cs:line 96 at 
Castle.Windsor.Proxy.DefaultProxyFactory.CreateProxyGenerationOptionsFrom(ProxyOptions proxyOptions, IKernel kernel, CreationContext context, ComponentModel model) in 
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Proxy\DefaultProxyFactory.cs:line 178 at
Castle.Windsor.Proxy.DefaultProxyFactory.Create(IKernel kernel, Object target, ComponentModel model, CreationContext context, Object[] constructorArguments) in 
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\Windsor\Proxy\DefaultProxyFactory.cs:line 105 at
Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) in 
c:\BuildAgent\work\5b096cace0fecb1f\src\Castle.Windsor\MicroKernel\ComponentActivator\DefaultComponentActivator.cs:line 123`
4

2 回答 2

3

我尝试运行您的代码,但它可以在我的机器上运行

在此处输入图像描述

于 2012-09-27T21:18:25.313 回答
3

这似乎是 Intellitrace 的一个问题,可以通过禁用它来解决:

  • 工具 -> 选项 -> IntelliTrace(取消选中启用 Intellitrace)

找到其他有类似问题的参考。

于 2012-10-01T14:27:38.220 回答