3

Trying to find the real cause of this and not having much fun!

Type is not resolved for member 'Castle.MicroKernel.Lifestyle.Scoped.CallContextLifetimeScope+SerializationReference,Castle.Windsor, Version=3.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'. 

This looks like a bug considering I have nothing register with the container using this lifestyle.

Code Jammr
  • 1,867
  • 3
  • 14
  • 18

2 Answers2

2

Faced same issue while doing MSTest. Adding Castle.Windsor.dll to GAC worked for me.

gacutil.exe /if "C:\Castle.Windsor.3.1.0\lib\net40\Castle.Windsor.dll"
SarkarG
  • 687
  • 1
  • 8
  • 30
  • 1
    That worked for me as well - I would love to know why though. This is kind of a workaround instead of a permanent solution for me. – thebeekeeper Jun 14 '13 at 17:15
  • This occurred in two machines only. I remember it breaks somewhere in nHibernate code while doing some Native to Managed Transition and vice versa. – SarkarG Jun 17 '13 at 10:36
  • Yeah, that's the same thing I was seeing. Adding Windsor to the GAC on all of our build/integration servers isn't a good solution for me, but I guess it'll have to work for now. – thebeekeeper Jun 17 '13 at 16:59
  • 1
    Updating Castle Windsor to the 3.2.1 has fixed this issue for me: http://www.castleproject.org/blog/2013/07/castle-windsor-3-2-1-bugfix-release/ – thebeekeeper Aug 09 '13 at 13:37
  • That's great. This bug was really annoying. I will upgrade to 3.2.1. Thanks. – SarkarG Aug 10 '13 at 14:43
1

I'm not sure what you are trying to do, but if your goal is implementing an IDependencyResolver (which looks like it since you are using scopes):

If you are implementing an IDependencyResolver, don't try to be clever and inherit from your IDependencyScope implementation. Create the Resolver from scratch. This is how I implemented my dependency resolver (which works):

public class WindsorDependencyResolver : IDependencyResolver {
    private readonly IWindsorContainer _container;

    public WindsorDependencyResolver(IWindsorContainer container)
    {
        _container = container;
    }

    public IDependencyScope BeginScope()
    {
        return new WindsorDependencyScope(_container);
    }

    public object GetService(Type serviceType)
    {
        return _container.Kernel.HasComponent(serviceType)
                   ? _container.Resolve(serviceType)
                   : null;
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _container.ResolveAll(serviceType).Cast<object>();
    }

    public void Dispose()
    {
    }
}

public class WindsorDependencyScope : IDependencyScope {
    private readonly IWindsorContainer _container;
    private readonly IDisposable _scope;
    private bool _disposed;

    public WindsorDependencyScope(IWindsorContainer container)
    {
        _container = container;
        _scope = _container.BeginScope();
    }

    public object GetService(Type serviceType)
    {
        EnsureNotDisposed();
        return _container.Kernel.HasComponent(serviceType)
                   ? _container.Kernel.Resolve(serviceType)
                   : null;
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        EnsureNotDisposed();
        return _container.ResolveAll(serviceType).Cast<object>();
    }

    public void Dispose()
    {
        if(_disposed) return;

        _scope.Dispose();
        _disposed = true;
        GC.SuppressFinalize(this);
    }

    private void EnsureNotDisposed()
    {
        if(_disposed) throw new ObjectDisposedException("WindsorDependencyScope");
    }
}

And this was my first attempt (which produced your error):

public class WindsorDependencyResolver : WindsorDependencyScope, IDependencyResolver {
    private readonly IWindsorContainer _container;

    public WindsorDependencyResolver(IWindsorContainer container)
        : base(container)
    {
        _container = container;
    }

    public IDependencyScope BeginScope()
    {
        return new WindsorDependencyScope(_container);
    }
}
Raphael R.
  • 23,524
  • 1
  • 22
  • 18
  • Well we are 100% on the same page, down to the implementation of IDependencyResolver and IDependencyScope. I am still trying to figure out this issue. It almost looks like a framework serialization issue but I have no proof of this yet. – Code Jammr Aug 12 '12 at 15:49
  • So to be clear I am still getting the error, using 3.1 of the container. – Code Jammr Aug 12 '12 at 16:20
  • At this point maybe I should troubleshoot things from a different angle since you are not having this issue. So here we go File new Project LOL.. UGH... Sometimes writing code just sucks. – Code Jammr Aug 12 '12 at 16:26
  • Hi, do you know what you have changed for it to work? It could be helpful for other people. Glad that you managed to work it out. – Raphael R. Aug 13 '12 at 16:01
  • I think downloading the latest build of MVC 4 may have fixed the problem but that is both vague and unreliable. – Code Jammr Aug 15 '12 at 12:27
  • Having this problem too...running latest updates of MVC and still have the problem. – Jeff Aug 17 '12 at 03:31
  • Also, I'm not subclassing anything - just implementing IDependencyResolver and IDependencyScope as described in various places. – Jeff Aug 17 '12 at 03:38