2

I'm in the process of upgrading from version 2.5.1 to version 3.1.0 and what used to work no long does. I'm attempting to resolve a factory that creates components that utilize generics. The error that is thrown is "ComponentActivator: could not proxy " where is the name of the factory that cannot be resolved

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());
    }
}

This code is utilized in the following fashion within an Entity Framework repository for passing the EntityContext to another repository in order to handle deleted object like so:

    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);                      
    }

Update: Including Inner Exception

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`
Randy
  • 1,955
  • 2
  • 15
  • 24

2 Answers2

3

I tried running your code, but it works on my machine

enter image description here

Krzysztof Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • Lovely! lol. I'll give it another go. Failed in my test project and in my sample app (code) above. I thought it was a bit weird as I have another project where this is working so perhaps my computer just needs a rest. I'll keep you posted. – Randy Sep 27 '12 at 22:45
  • Krzysztof - I updated the question to include the inner exception. I also posted an answer on how I resolved the issue (thanks to a similar post; different library). Since 2.5.1 worked and 3.1.0 failed when Intellitrace was on, I'm assuming something within the library changed with respect this this functionality. I'm not using Intellitrace at this time so leaving it off is is no big deal. – Randy Oct 01 '12 at 14:36
3

This appears to be an issue with Intellitrace and is resolved by disabling it:

  • Tools -> Options -> IntelliTrace (uncheck Enable Intellitrace)

Found a reference to others having a similar issue.

Community
  • 1
  • 1
Randy
  • 1,955
  • 2
  • 15
  • 24
  • I tried too, but it isn't working .. I have the same issue .. check out my code here http://stackoverflow.com/questions/14750615/exception-componentactivator-could-not-proxy-asfactoryimplementation-factory – Ramesh Karna Feb 08 '13 at 05:04