2013-07-31 1 views
4

나는 유형 해결하려고 시도 할 때 다음과 같은 오류가 무엇입니까 :유형에 동일한 길이 1 여러 생성자를 선택할 수 없습니다 '선택 System.String'

유형에 동일한 길이 1을 사용하여 여러 생성자를 선택할 수 없습니다 '를 System.String '. 구성 요소가 등록 될 때 UsingConstructor() 구성 메소드를 사용하여 명시 적으로 생성자를 선택하십시오.

유형은 System.String이 사진에오고 어디 그래서 난 정말 지 모르겠 IRepositoryILog 소요 한 생성자를 가지고있다. 나는 당혹 스럽다. 누구든지 문제가 뭔지 알 수 있습니까? 여기

스택 트레이스이다 Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance에서 Autofac.Core.Activators.Reflection.MostParametersConstructorSelector.SelectConstructorBinding에서

([] ConstructorParameterBinding constructorBindings) (IComponentContext 문맥 ,는 IEnumerable 1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable 1 파라미터) Autofac.Core.Resolving.InstanceLookup.Execute() Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance (ISharingLifetimeScope currentOperationScope, IComponentRegistration 등록시 에서, 파라미터는 IEnumerable 1 parameters) at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable 1),536,at Autofac.Core.Activators.Reflection.AutowiringParameter. <> C_ DisplayClass2.b _0()에서 Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()에서 (IComponentContext 컨텍스트를 IEnumerable 1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable 1 파라미터)에 Autofac.Core.Resolving.InstanceLookup.Execute()에서 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance (ISharingLifetimeScope currentOperationScope, IComponentRegistration 등록, IEnumerable을 1 parameters) at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable 1 파라미터)에 Autofac.Core.Activators.Reflection.AutowiringParameter . <> C_ DisplayClass2.b _0()에서 Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()에서 (IComponentContext 컨텍스트를 IEnumerable 1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable 1 파라미터)에 IEnumerable을 Autofac.Core.Resolving.ResolveOperation.Execute에서 Autofac.Core.Resolving.InstanceLookup.Execute()에서 Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance (ISharingLifetimeScope currentOperationScope, IComponentRegistration 등록, IEnumerable을 1 parameters) at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable 1 파라미터) (IComponentRegistration 등록, 1 parameters) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable 매개 변수 1 개) (Autofac.ResolutionExtensions.TryResolveService (IComponentContext c 타세, 서비스의 서비스를 IEnumerable 1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable 1 매개 변수) Autofac.ResolutionExtensions.Resolve (IComponentContext 컨텍스트 유형 ServiceType 자리에서 , IEnumerable을 1 parameters) at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) at SomeCompany.ComponentModel.Composition.AutofacIocContainer.Resolve(Type type) in c:\SomeCompany.Core\ComponentModel\Composition\AutofacIocContainer.cs:line 17 at SomeCompany.Commands.CommandFactory.Create(String name) in c:\SomeCompany.Core\Commands\CommandFactory.cs:line 28 at SomeCompany.Web.Controllers.CommandsController.Post(String id, String request) in c:\SomeCompany.Web\Controllers\CommandsController.cs:line 49 at lambda_method(Closure , Object , Object[]) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func 1 FUNC, CancellationToken cancellationToken)

+0

IRepository 및 ILog는 무엇을 해결합니까? 이러한 인터페이스를 구현하는 클래스의 생성자는 문자열 param을 사용하거나 문자열 param이있는 생성자가있는 종속성을 가질 수 있습니다. –

+0

구성 및 확인중인 유형의 정의를 표시하십시오. 의존성 중 하나 (IRepository, ILog 또는 그 종속성이 재귀 적으로)에 여러 생성자가 포함될 수 있습니까? Doensn't Autofac은 타입 이름을 던집니다 (아마도 내부 예외에서)? – Steven

+2

혹시 이것을 알아 냈습니까? – ps2goat

답변

4

이 자신의 코드에 여러 constuctors 함께 할 수 없다 !

Autofac은 사용자가 직접 명시 적으로 설정하지 않으면 자동으로 생성자의 개체를 만듭니다.

그러나 String에 매개 변수없는 생성자가 없으므로 생성자에 String 매개 변수가 있으면 문자열을 만들 수 없습니다![1]

대상의 생성자에서 모든 문자열을 명시 적으로 설정해야합니다. NamedParameters를 사용하여 String에 명시적인 값을 부여 할 수도 있습니다.

행운을 빈다.

[1] http://msdn.microsoft.com/en-us/library/system.string%28v=vs.110%29.aspx

+6

이것은 정답이지만, Autofac의 좀 더 유익한 디버그 정보가 있습니다. 복잡한 컨테이너가 모든 의존성을 거쳐 트롤링되면서 문자열이있는 문자열을 찾아내는 것이 다소 고통 스럽습니다. – Shaun

0

는 데이터베이스 정의 파일 (하면 .dbml)가있는 경우, 당신은하지 않았다 코드 수정을 확인합니다. 이 작업을 수행하여

public JudicialDataContext(string connection) : base(connection, mappingSource) 
{ 
    OnCreated(); 
} 

는이, 또는 무엇을 달성하려고했던 이유는 아무 생각이 없다, 또는 왜이 변경 : 내 경우, 다음과 같은 방법

public JudicialDataContext(string connectionString) : base(connectionString, mappingSource) 
{ 
    OnCreated(); 
} 

이 변경되었습니다 심지어 필요할 것입니다. 그러나 변경을 취소하고 다시 컴파일하면이 오류가 해결되었습니다.

관련 문제