Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 合并程序集的Autofac解决问题_.net_Autofac_Ilmerge - Fatal编程技术网

.net 合并程序集的Autofac解决问题

.net 合并程序集的Autofac解决问题,.net,autofac,ilmerge,.net,Autofac,Ilmerge,我们正在使用Autofac编写我们的WPF应用程序,并以这种方式对许多涉及的项目使用自动注册: builder.RegisterAssemblyTypes(type).AsSelf().AsImplementedInterfaces().PreserveExistingDefaults(); 除此之外,我们还明确注册了许多类型的单身生活方式和一些Func工厂。工厂的注册通常如下所示: builder.Register( c=> { var context=c.Resolve(); 返回(参数)

我们正在使用Autofac编写我们的WPF应用程序,并以这种方式对许多涉及的项目使用自动注册:

builder.RegisterAssemblyTypes(type).AsSelf().AsImplementedInterfaces().PreserveExistingDefaults();
除此之外,我们还明确注册了许多类型的单身生活方式和一些
Func
工厂。工厂的注册通常如下所示:

builder.Register(
c=>
{
var context=c.Resolve();
返回(参数)=>context.Resolve(
新类型参数(类型(参数类型),参数);
});
所有这些注册在逻辑上分组在按顺序注册的多个模块中

在我们开始合并一些相关的程序集之前,所有这些都可以正常工作。我们需要这样做,因为我们必须混淆部分代码,所有混淆的程序集必须合并,才能“找到”彼此的类型。出于同样的原因,我们还合并到Autofac程序集中

在合并的应用程序中,解析简单的实例注册工作正常

但是,解决应用程序的复杂主视图模型时,会发生以下异常:

Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Autofac.Core.Registration.ScopeRestrictedRegistry' can be invoked with the available services and parameters:
Cannot resolve parameter 'System.Object scopeTag' of constructor 'Void .ctor(System.Object)'.
   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.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.InstanceLookup.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 ApplicationModulesModule.<Load>b__1(IComponentContext c) in d:\Development\Production\Application\Application.Shell\AutofacSetup.cs:line 239
   at Autofac.RegistrationExtensions.<>c__DisplayClass10`1.<Register>b__f(IComponentContext c, IEnumerable`1 p)
   at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
   at Autofac.Core.Activators.Delegate.DelegateActivator.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)
   at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.TryResolve(IComponentContext context, Type serviceType, Object& instance)
   at CaliburnBootstrapper.GetInstance(Type serviceType, String key) in d:\Development\Production\Application\Application.Shell\CaliburnBootstrapper.cs:line 102
   at Caliburn.Micro.BootstrapperBase.DisplayRootViewFor(Type viewModelType, IDictionary`2 settings)
   at CaliburnBootstrapper.<StartShell>b__13() in d:\Development\Production\Application\Application.Shell\CaliburnBootstrapper.cs:line 254
   at CaliburnBootstrapper.StartShell() in d:\Development\Production\Application\Application.Shell\CaliburnBootstrapper.cs:line 254
   at CaliburnBootstrapper.<>c__DisplayClass21.<GetConfiguredApplicationUpdater>b__18(Object o, FailArgs args) in d:\Development\Production\Application\Application.Shell\CaliburnBootstrapper.cs:line 340
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Autofac.Core.DependencyResolutionException:在类型“Autofac.Core.Registration.ScopeRestrictedRegistry”上使用“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”找到的构造函数都不能使用可用的服务和参数调用:
无法解析构造函数“Void.ctor(System.Object)”的参数“System.Object scopeTag”。
在Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext上下文,IEnumerable`1参数)中
在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.Execute()处
在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(iShareInLiFeTimeScope currentOperationScope,IComponentRegistration,IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.ResolveComponent处(IComponentRegistration注册,IEnumerable`1参数)
在Autofac.Core.Activators.Reflection.AutowiringParameter.c__DisplayClass2.b__0()中
在Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()中
在Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext上下文,IEnumerable`1参数)中
在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.Execute()处
在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(iShareInLiFeTimeScope currentOperationScope,IComponentRegistration,IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.ResolveComponent处(IComponentRegistration注册,IEnumerable`1参数)
在Autofac.Core.Activators.Reflection.AutowiringParameter.c__DisplayClass2.b__0()中
在Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()中
在Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext上下文,IEnumerable`1参数)中
在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.Execute()处
在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(iShareInLiFeTimeScope currentOperationScope,IComponentRegistration,IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.ResolveComponent处(IComponentRegistration注册,IEnumerable`1参数)
位于Autofac.ResolutionExtensions.TryResolveService(IComponentContext上下文、服务服务、IEnumerable`1参数、对象和实例)
在Autofac.ResolutionExtensions.ResolveService(IComponentContext上下文、服务服务、IEnumerable`1参数)处
在Autofac.ResolutionExtensions.Resolve处(IComponentContext上下文,类型serviceType,IEnumerable`1参数)
在Autofac.ResolutionExtensions.Resolve[TService](IComponentContext上下文,IEnumerable`1参数)
在Autofac.ResolutionExtensions.Resolve[TService](IComponentContext上下文)
在d:\Development\Production\Application\Application.Shell\AutofacSetup.cs中的ApplicationModules.b_u1(IComponentContext c):第239行
在Autofac.RegistrationExtensions.c_uuDisplayClass10`1.b_uf(IComponentContext c,IEnumerable`1p)
在Autofac.Builder.RegistrationBuilder.c__中显示Class1`1.b__0(IComponentContext c,IEnumerable`1p)
位于Autofac.Core.Activators.DelegateActivator.ActivateInstance(IComponentContext上下文,IEnumerable`1参数)
在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.Execute()处
在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(iShareInLiFeTimeScope currentOperationScope,IComponentRegistration,IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.ResolveComponent处(IComponentRegistration注册,IEnumerable`1参数)
在Autofac.Core.Activators.Reflection.AutowiringParameter.c__DisplayClass2.b__0()中
在Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()中
在Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext上下文,IEnumerable`1参数)中
在Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1参数)处
在Autofac.Core.Resolving.InstanceLookup.Execute()处
在Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(iShareInLiFeTimeScope currentOperationScope,IComponentRegistration,IEnumerable`1参数)处
在Autofac.Core.Resolving.ResolveOperation.ResolveComponent处(IComponentRegistration注册,IEnumerable`1参数)
在Autofac.Core.Resolving.ResolveOperation.Execute处(IComponentRegistration注册,IEnumerable`1参数)
在Autofac.Core.Lifetime.LifetimeScope.com上