System.AccessViolationException exception while accessing local resources in mvc

Today I have met a very strange behaviour of mvc.

I migrated my old mvc3 project to mvc4 and tried to run it up, but IIS Express died with an exception.

Debugging in Visual Studio did not give any information. It threw an exception on every try to access local resources.

The exception text is: An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.

And the method which caused the exception is:

public static string LocalResource(this WebViewPage page, string key)
    return page.ViewContext.HttpContext.GetLocalResourceObject(page.VirtualPath, key) as string;

I have spent a couple of hours trying to understand what may cause such a strange exception. In the end I figured out that the LocalResource method is defined in Helpers project, which is still using mvc3.

Conclusion: If you try to access local resources from a dll which references mvc3 from a mvc4 project it will end up with System.AccessViolationException exception.

Views: 4185 Comments: 0
It's sad to say, but..
Due to the enormous amount of spam I have decided to disable comments on my website. Feel free to contact me through any other available channel.