I was faced with a somewhat unexpected MissingMethodException changing a property type from string to XhtmlString while making changes to an Optimizely website for my current client. I’ve done this sort of change on mant occations, and moving from a string to an XhtmlString should not cause a problem.
[Display(
Name = "Brödtext",
GroupName = SystemTabNames.Content,
Order = 110,
Description = "")]
public virtual string Preamble { get; set; }
The exception seemed to be thrown on a simple Html.PropertyFor call in the view file.
[MissingMethodException: Method not found: System.String XX.Core.Models.Blocks.SomeBlock.get_Preamble().]
ASP._Page_Views_Shared_Blocks_SomeBlock_cshtml.Execute() in C:\Path\XX\Views\Shared\Blocks\SomeBlock.cshtml:11
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
This type of problem occurs when there is a binary mismatch, i.e. you have compiled code where you try to call the property getter, that is supposed to return a string, but now returns an XhtmlString. So there is a mismatch between what is compiled and what is in the code.
The solution is quite simple. It is likely enough just to stop the website, clean the temporary ASP-NET files (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\), and restart the website again.
If it doesn’t work, try:
- Closing your IDE, remove bin and obj directories, rebuild the entire solution.
- Clean the temporary ASP.NET files as mentioned.
- Run IISRESET.
- Make sure your views do not try to use the property as a string.
This may occur if there is a view precompiled with an old assembly, or if the server wasn’t restartade. Then the old signature may still be in memory.
Also, if you only deploy certain files, old assemblies or views may still be there.
Also, ASP.NET may cache views and assemblies.