Unblocking Assembly Due to AspNetHostingPermission Security Exception

Ok, I am one of those strange birds who jumped over Windows Vista and went straight from Windows XP to Window 7, so I havenโ€™t had the pleasure to experience many of the security features that supposedly protect the user from themselves.

After banging my head on the proverbial wall one too many times, I finally figured out the cause of a Security Exception I was getting while trying to add xVal Validation Framework into my ASP.NET MVC v2 Preview 1 project.

โ€œSystem.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.โ€

SecurityException

It appears that Windows 7 (and from what Iโ€™ve heard Windows Vista also does this as well) attempted to protect me from a potential threat! When looking at the file properties dialog of the xVal.dll there was a security message at the bottom statingโ€ฆ

โ€œThis file came from another computer and might be blocked to help protect this computer.โ€

UnblockAssemblyIt turns out that all I had to do is click the โ€œUnblockโ€ button next to the message, remove & readd my Visual Studio project reference, and viola my problems were solved!

Next time, I hope not to waste half my day trying to figure this out. If you have not already faced this pain, I hope that you donโ€™t have to in the future, or that this post will help you resolve it quickly!

If you enjoyed this post, please consider sharing it with others via the following Twitter or Reddit buttons. Also, feel free to checkout my egghead.io profile page for addition free and subscription lessons, collections, and courses. As always, you can reach out to me on Twitter at @elijahmanor. Thanks and have a blessed day!

Reddit