MVC5 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException

前端 未结 7 1932
春和景丽
春和景丽 2021-02-01 21:52

Ive been working on converting a MVC4 project over to MVC5. The first day I ran into an \'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException\' but was able to resolve it by s

相关标签:
7条回答
  • 2021-02-01 22:28

    I also hit this issue with VS 2013 U3. I had just added an email field to RegisterViewModel with the [EmailAddress] attribute, and it was crashing when I tried visiting the Register page. Commenting out the [EmailAddress] attribute fixed the issue. However, it continued working after I added the attribute back in, so this is probably a broader issue that could have to do with changes to the model classes.

    0 讨论(0)
  • 2021-02-01 22:29

    Check the views in the Account folder and for each one that has an explicit model, make sure the (view)model is in the right namespace. Mouse over the m parameter (m => m.UserName ... etc) and make sure it is referencing the correct (view)model. In my case, I moved AccountViewModels to a different folder and the app broke as above. It appears the views are sort of "caching" the model from the original namespace. I used a silly fix (commented out the @model line and un-commented it back). Got warning that m is dynamic but when built and ran it worked. Looks like a glitch in VS 2013 RTM.

    0 讨论(0)
  • 2021-02-01 22:32

    This bug is verified by Microsoft, and they are working on fixing it.

    So anyone from the future who reads this: try updating visual studio 2013 to at least update 2.

    https://connect.microsoft.com/VisualStudio/feedback/details/813133/bug-in-mvc-5-framework-asp-net-identity-modules

    0 讨论(0)
  • 2021-02-01 22:32

    Found a solution for my own (mvc5) project after some experimenting.

    I had a _ExternalLoginsListShoppingCartPartial.cshtml (from my mvc4 project) with @model ICollection<AuthenticationClientData> at the top. I commented it out and rebuild the solution and suddenly it works. I'm not even using that partial view in any view so it's a pretty nasty bug imo.

    So check in your project. You may have some mvc4/simplemembership stuff that is messing up your mvc5 project.

    0 讨论(0)
  • 2021-02-01 22:32

    For me I had changed the contents of the ManageUserViewModel to add a property... I then started getting the error. When I changed the Manage.cshtml from not using an explicit model to using:

    @model XYZ.Models.ManageUserViewModel

    and removed the using statements, it started working again. One hour wasted!

    0 讨论(0)
  • 2021-02-01 22:34

    I got the same error after replacing account models to another folder. When I double checked each view under the Account folder I found out my "Manage.cshtml" referenced to old namespace. I changed it to correct namespace for my models and the error fixed.

    0 讨论(0)
提交回复
热议问题