2015-02-03 1 views
1

Web Application이 Asp.NET (4.5) 및 Simple Injector에 있습니다. 모든 응용 프로그램이 올바르게 작동하고 Simple Injector도 작동합니다. 나는이 라벨 얻으려고ASP.NET WebForms 및 SimpleInjector FindControl에서 매개 변수없는 생성자가 발생하지 않습니다.

<asp:FormView ID="MyFv" runat="server"> 
          <InsertItemTemplate> 
           <label id="myLblTest" runat="server">fffff</label> 
          </InsertItemTemplate> 
         </asp:FormView> 

을 그리고 연사 :

protected void Page_Load(object sender, EventArgs e) 
     { 
      Control testDDL = MyFv.FindControl("myLblTest"); 

을하지만 testDDL가 null 및 ObjectDataSource를 더 복잡 formviews 함께이 예외가 발생합니다 :

을 그러나 문제는 FormView 함께
For this object is not defined constructor with no parameters 

스택 트레이스 :

w System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
     w System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
     w System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) 
     w System.Activator.CreateInstance(Type type, Boolean nonPublic) 
     w System.Activator.CreateInstance(Type type) 
     w System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) 
     w System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) 

동일한보기가 웹 사이트에 있었고 SimpleInjector 없이도 아무 문제없이 작동했습니다.

감사합니다.

+0

컨트롤러가 컨테이너에 등록되어 있습니까? – janhartmann

+0

ASP.NET WebForms에는 컨트롤러가 없습니다. 컨테이너에서 하위 계층의 클래스 등록 : 비즈니스 계층 및 데이터 액세스 계층 – Robert

+0

아, 죄송합니다. 내 잘못 - SImple Injector는 어떻게 설정되어 있습니까? 전체 페이지 소스를 볼 수 있습니까? http://simpleinjector.readthedocs.org/en/latest/webformsintegration.html – janhartmann

답변

1

문제는 ObjectDataSource에서 발생했습니다. EventCreating 이벤트에서 매개 변수없는 생성자가있는 ObjectDataSource 클래스에 할당되었으며 이제는 작동합니다.

관련 문제