1

I have Web Application in Asp.NET (4.5) and Simple Injector. All application works right and Simple Injector too. But the problem is with FormView:

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

And in cs I try to get this label:

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

but testDDL is null and with more complicated formviews with ObjectDataSource it throws an exception:

For this object is not defined constructor with no parameters

StackTrace:

 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)

When this same view was in Website and without SimpleInjector it worked without any problem.

Thanks

Robert
  • 2,571
  • 10
  • 63
  • 95
  • Are the controllers registered in the container? – janhartmann Feb 03 '15 at 11:55
  • ASP.NET WebForms don't have controllers. In container are registered class from bottom layer: business layer and data access layer – Robert Feb 03 '15 at 11:59
  • Oh, sorry. My bad - How is your SImple Injector set up? And can I see the whole Page source? Also see the paragraph of: http://simpleinjector.readthedocs.org/en/latest/webformsintegration.html – janhartmann Feb 03 '15 at 12:08
  • What do you mean with "When this same view was in Website and without Simple Injector it worked without any problem."? This seems higlly unlikely, because Web Forms can't handle anything but default constructors. So that view cannot have worked anyhow. – Steven Feb 03 '15 at 12:17

1 Answers1

1

The problem was with ObjectDataSource. In event ObjectCreating I assigned to ObjectDataSource class that have parameterless constructor and now it works.

Robert
  • 2,571
  • 10
  • 63
  • 95