This project is read-only.

Assembly MvcCodeRouting is partially trusted

Mar 19, 2015 at 1:08 AM
MvcCodeRouting was working fine for months. Suddenly it started to throw this error:

Assembly 'MvcCodeRouting, Version=, Culture=neutral, PublicKeyToken=bf7cf9743009fe42' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself. In order to access security critical code, this assembly must be fully trusted.

Exception Details: System.MethodAccessException: Attempt by security transparent method 'MvcCodeRouting.Web.Mvc.MvcControllerInfo.Create (System.Type, MvcCodeRouting.RegisterSettings, MvcCodeRouting.CodeRoutingProvider)' to access security critical method 'System.Runtime.Serialization.FormatterServices.GetUninitializedObject(System.Type)' failed.

I found this article from microsoft:
Using Libraries from Partially Trusted Code

It's not clear to me what really happened.
I think my host provider just enabled some security stuff.
It seems to me that you have to flag your assembly for use in "medium trust" context.
"There is no programmatic way for partially trusted code to call a library that does not have the AllowPartiallyTrustedCallersAttribute attribute."
Is that right?
How can I fix this?
Thanks in advance.
Mar 19, 2015 at 2:31 AM
Medium trust is obsolete, so developing for it is not worth it. At the same time, that code enables a very obscure feature that I'm sure no one uses, and the whole described-based metadata is pretty much broken since MVC 4, so I should just remove all that.

In the meantime, try this:
  1. Fork the code.
  2. Remove everything in MvcControllerInfo.Create except the last line where it returns ReflectedMvcControllerInfo. You can also remove the type constructor and related fields.
  3. Build and replace MvcCodeRouting.dll in your production website with your modified assembly.
Let me know if that works.
Marked as answer by LeandroMBarreto on 3/18/2015 at 8:01 PM
Mar 19, 2015 at 4:08 AM
It worked by just cleaning up MvcControllerInfo.Create as you said and rebuilding my project.

I accidentaly made a pull request to master branch.
I'm new to github. ^^

So, the problem is that my provider should allow us to run under Full Trust?
Hope they do that.
Mar 19, 2015 at 5:37 AM
Yes, there are no issues on full trust.

BTW, I'll eventually make this change, not sure when though.