SecurityException: That assembly does not allow partially trusted callers.
By rickvdbosch
- 2 minutes read - 278 wordsThe exception mentioned in the title of this post was the one I encountered when using an ASP.NET control I had written.
**How I encountered the exception:
** Because I develop several websites, there’s a lot of functionality I need more than once. A possible solution for this is to write a control gallery containing the functionality I needed. And putting them in a seperate assembly makes it easy to dstribute them freely in the near future ;). I made the assembly (containing an image gallery and a download gallery) and used it in a website I am developing together with a good friend of mine. There were no problems and life seemed good. Until the day came we published the website. After putting the website online, one of the pages was not rendering correctly, displaying the message “Unhandled Exception: System.Security.SecurityException: That assembly does not allow partially trusted callers”.
The reason for the exception:
Lots of providers don’t run websites in Full Trust mode. Because of that some actions you can take inside a (referenced) assembly aren’t allowed. For me I’m not sure if the problem was the scanning of the hard drive or the fact I get embedded images from the assembly. One way or the other: there was stuff in there which wasn’t allowed ;).
Taking care of the exeption:
The solution I used to solve this problem was pretty straight-forward: I added the AllowPartiallyTrustedCallersAttribute to the assembly. Another solution could have been to extract the controls from the seperate assembly and put them inside the website, but I didn’t prefer that. This article on the .NET security blog explains a bit more about the AllowPartiallyTrustedCallersAttribute…