dongfo / autofac

Automatically exported from code.google.com/p/autofac
0 stars 0 forks source link

Issue with latest version of Autofac #374

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We've been using Autofac for a while now in our .NET and SL4 code. I tried to 
upgrade to 2.6.2.859 tonight, and all tests passed save for one in the SL4 
code. The test builds up a ContainerBuilder, and when this line of code is 
called:

var viewModel = builder.Build().Resolve<MainViewModel>();

the following exception is thrown:

Autofac.Core.DependencyResolutionException occurred
  Message=An exception was thrown while executing a resolve operation. See the InnerException for details.
  StackTrace:
       at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Container.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
       at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
       at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
       at ClientCode.UI.Tests.ViewModels.MainViewModelTests.Create()
  InnerException: System.MethodAccessException
       Message=Attempt by method 'System.Linq.Expressions.Expression.CreateLambda(System.Type, System.Linq.Expressions.Expression, System.String, Boolean, System.Collections.ObjectModel.ReadOnlyCollection`1<System.Linq.Expressions.ParameterExpression>)' to access method 'System.Linq.Expressions.Expression`1<Autofac.Core.Activators.Reflection.ConstructorParameterBinding+ConstructorInvoker>.Create(System.Linq.Expressions.Expression, System.String, Boolean, System.Collections.ObjectModel.ReadOnlyCollection`1<System.Linq.Expressions.ParameterExpression>)' failed.
       StackTrace:
            at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
            at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
            at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            at System.Linq.Expressions.Expression.CreateLambda(Type delegateType, Expression body, String name, Boolean tailCall, ReadOnlyCollection`1 parameters)
            at System.Linq.Expressions.Expression.Lambda(Type delegateType, Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
            at System.Linq.Expressions.Expression.Lambda(Type delegateType, Expression body, ParameterExpression[] parameters)
            at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.GetConstructorInvoker(ConstructorInfo constructorInfo)
            at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
            at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
            at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
            at Autofac.Core.Resolving.InstanceLookup.Execute()
            at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
            at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
            at Autofac.Core.Activators.Reflection.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0()
            at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
            at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
            at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
            at Autofac.Core.Resolving.InstanceLookup.Execute()
            at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
            at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
            at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
       InnerException: 

This didn't happen with the previous version. Our .NET code does not have any 
issues; only the SL4 one does.

Any insight as to why this is suddenly failing?

Original issue reported on code.google.com by jason.bo...@gmail.com on 14 Jun 2012 at 2:02

GoogleCodeExporter commented 8 years ago
Thanks for the report, Jason. We made some optimisations in the 2.6.2 release 
that appear to be incompatible with the Silverlight security model, we'll look 
into this. In the meantime, rolling back to 2.6.1 is the best idea.

Cheers,
Nick

Original comment by nicholas...@gmail.com on 16 Jun 2012 at 3:09

GoogleCodeExporter commented 8 years ago
I am fairly sure that rev 941 fixes the issue; it removes the LambdaExpression 
code from the Silverlight build. The WINDOWS_PHONE condition has been replaced 
with SILVERLIGHT because that condition is defined for both the Silverlight and 
WP7 builds. I figured that as we move towards Portable Libraries support that 
any code that does not work across all supported targets for the profile should 
be excluded.

Original comment by alex.meyergleaves on 17 Jun 2012 at 2:34