There. I said it. Medium Trust is PITA. I wont be surprised if someone replies with one of the following:
“Well, not really, you only have to do x, y and z and your code is compatible with medium trust environments”
or
“It’s there (Medium Trust) because code needs boundaries within controlled scenarios such as hosting environments.. “
Blah. Blah. Blah. You’re both right. However, it’s still a PITA. Why? In the past 4 months I’ve spent countless hours figuring out why my app is broken in a medium trust environment. I use certain tools to make my life easier (such as Castle Active Record, Windsor, ASP.NET MVC, Spark, etc) yet a lot of them assume full trust. They do have options to get them running under partial/medium trust but in my experience the debugging of these tools in said environments sucks.
Needless to say, I just got done debugging for 2.5 hours why my Spark MVC site would not precompile my views. The error was “No Input could be found". WTH!?! Finally, after walking through my app line by line I found the following in a Spark view:
${Html.ActionLink("Track Admin", "index", new { controller = "track" })} ${Html.ActionLink("Speaker Admin", "index" , new {controller="speaker"})}
The problem is that I had deleted those controllers and moved that part of the app. Once I removed the code, it recompiled fine. Completely frustrating and the root cause of this is Medium trust. I just spent 2.5 hours working on a debugging issue for Medium trust when I could be creating my app for a mobile start up company that I’m heading up.
Long story short : I’m not a fan of Medium Trust. I don’t know many people who are.
How Can we Get Around It?
I’m not sure we can in the .NET space. Other dynamic languages don’t seem to have these issues, but they do run into odd edge cases at runtime which can be even more of a pain to handle. So at this point, the only answer I have is to recommend any open source or commercial vendor to test their product on a lock down medium trust environment and provide very clear and concise instructions for how to get their product to run under medium trust.