daveaglick / FluentBootstrap

Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
http://www.fluentbootstrap.com
MIT License
200 stars 76 forks source link

Error: A Bootstrap component is finishing but is not at the top of the stack #43

Closed mahmoodvcs closed 9 years ago

mahmoodvcs commented 9 years ago

I have a simple form that works fine on my machine but gives me error on production server:

System.InvalidOperationException: A Bootstrap component is finishing but is not at the top of the stack, which is usually an indication that a component has been disposed out of order or that more than one component was created in a single using statement.

Source Error: 

Line 13: {
Line 14:     @form.EditorFor(m => m.FirstName);
Line 15: }  <<== error line
Line 16: 

Source File: c:\Article27\Views\Engineers\New.cshtml    Line: 15 

Stack Trace: 

[InvalidOperationException: A Bootstrap component is finishing but is not at the top of the stack, which is usually an indication that a component has been disposed out of order or that more than one component was created in a single using statement.]
   FluentBootstrap.Component.Finish(TextWriter writer) +327
   FluentBootstrap.Component.End(TextWriter writer) +49
   FluentBootstrap.ComponentWrapper`2.End() +18
   ASP._Page_Views_Engineers_New_cshtml.Execute() in c:\Article27\Views\Engineers\New.cshtml:15
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
...

this is the code in the form:

@using (var form = Html.Bootstrap().Form(FormMethod.Post)
    .SetHorizontal().AddAttribute("enctype","multipart/form-data").Begin())
{
    @form.EditorFor(m => m.FirstName);
}

the original form had more controls but I removed other parts to find problematic part. and I still see the error even with a single control on the form. It seems like a bug.

daveaglick commented 9 years ago

Thanks for reporting this - sorry for the delay in responding. I haven't had a chance to look at it yet, hopefully I'll be able to dig in sometime this week. It's interesting that it's different based on the platform. The message you're seeing is a safety check designed to make sure that the FluentBootstrap control stack doesn't get corrupted. Can you provide any more information about the environments (OS, .NET runtime version, Visual Studio/IIS version, etc.)?

mahmoodvcs commented 9 years ago

Hi. Thank you for your response. I published all the files again on the server and the problem went away. But now in another project that I started recently, I have the same problem on my dev machine. The problem occurs if I'm using @form.EditorFor and I have a UIHint attribute on the model property and defined an EditorTemplate. I'm using Visual Studio 2015 and .Net 4.5 on Windows 10. In the other project I have the same situation but it works fine.

mahmoodvcs commented 9 years ago

I realized that it will happen when I have an error in my editor template. But instead of seeing the actual error I see this error. Thanks for your support.