Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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
C#Autofac-System.MissingMethodException:无法创建接口实例_C#_Autofac - Fatal编程技术网

C#Autofac-System.MissingMethodException:无法创建接口实例

C#Autofac-System.MissingMethodException:无法创建接口实例,c#,autofac,C#,Autofac,我试图使用Autofac注册两个实现,但我得到了上面的错误。 我注册了泛型类 ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor()' on type 'Application`1'. ---> System.MissingMethodException: Cannot create an instance

我试图使用Autofac注册两个实现,但我得到了上面的错误。 我注册了泛型类

---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor()' on type 'Application`1'.
---> System.MissingMethodException: Cannot create an instance of an interface.
builder.RegisterGeneric(typeof(ClassA)).As(typeof(IClassA)).InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(ClassB)).As(typeof(IClassB)).InstancePerLifetimeScope();
控制器上的ClassA实现如下所示:

builder.RegisterGeneric(typeof(ClassA<>)).As(typeof(IClassA<>)).InstancePerLifetimeScope();
builder.RegisterGeneric(typeof(ClassB<,>)).As(typeof(IClassB<,>)).InstancePerLifetimeScope();
专用只读IClassA\u classA;
公共类控制器(IClassA classA){
_classA=classA;
}

任何人都可以帮我解决这个问题,或者我遗漏了什么吗?

我对我的问题的回答是,在Autofac中,我们不应该手动初始化我们引用到接口的类,因为它将生成此类错误。它与属性自动关联,无需重新初始化。如果Instance==null,我将删除检查,然后我将创建新的ClassA来提供实例。

ClassA和
ClassB
的构造函数是什么样的
ClassA
Application1
?我怀疑某个类型注册错误,可能已将接口注册为类型,而不是将类型注册为接口。它可能是
应用程序
类。什么是
应用程序
?@weichch和Cyril Durand,无论应用程序是否替换为ClassA。最初我只是更改了它的应用程序名称,但它是相同的。您能
ClassA
确定它是一个类而不是一个接口吗?
private readonly IClassA<IClassB<OtherA, OtherB>> _classA;
public ClassController(IClassA<IClassB<OtherA, OtherB>> classA){
    _classA = classA;
}