저는 한동안 Autofac을 사용해 왔지만 완벽하게 작동했습니다.값은 null 일 수 없습니다. 매개 변수 이름 : 클래스를 해결하려고 할 때의 컨텍스트
최근에 다른 프로젝트에서이 프로젝트를 구현하고자 할 때 나는 왜 그것이 발생했는지 또는 그것이 어디에서 생길 수 있는지 전혀 알 수 없다는 예외가 발생했습니다.
System.ArgumentNullException : ". 값은 null 일 수 없습니다 매개 변수 이름 : 상황"
Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters)
Autofac.ResolutionExtensions.Resolve(IComponentContext context)
AssetManagement.App.Test.Main(String[] args) in Test.cs: line: 24
System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
System.Threading.ThreadHelper.ThreadStart_Context(Object state)
System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
System.Threading.ThreadHelper.ThreadStart()
App.cs :
public class Test
{
public static void Main(string[] args)
{
var scheduledJob = Startup.Container.Resolve<IScheduledJob>(); // Exception on this line
}
}
Startup.cs :
internal static class Startup
{
public static IContainer Container { get; private set; }
public static void Run()
{
var builder = new ContainerBuilder();
builder.RegisterType<Test.ScheduledJobTest>().As<IScheduledJob>();
Container = builder.Build();
}
}
Startup
에 구성 요소를 등록했는지 여부에 관계없이 이상한 점은 아무 문제가 없습니다.
또 다른 독특한 점은 내가 해결하려고하는 클래스에 관계없이 오류가 발생한다는 것입니다.
같은 오류는 다음과 같은 코드로 나에게 주어집니다 :
var scheduledJob = Startup.Container.Resolve<Exception>();
어디에서'Startup.Run'을 호출합니까? –