Saturday, January 17, 2009

Windows 7 - Silverlight/ASP.NET Development - That assembly does not allow partially trusted callers


NOTE: This article is related to the Windows Beta. The accuracy of this article may change

Today I ran into an exception that stated: "That assembly does not allow partially trusted callers". This exception was thrown when I ran my server code on Windows 7 Beta. However, the same code did not throw an exception while running from Windows Vista. I think this problem is something that other Silverlight and ASP.NET developers may run into. Because of this fact, I decided to toss together a blog post related to it. This post will provide the background of the problem and the solution I came to.

I had a basic Silverlight 2 input form application. This application connects to a standard .asmx running in a Windows 7 Beta environment. This .asmx uses the Enterprise Library to connect to a SQL Server 2005 instance. This SQL Server instance resides in the same Windows 7 Beta environment. When executing the code, I received an exception that stated: "That assembly does not allow partially trusted callers". Significantly, this exact code worked perfectly on Windows Vista.

After searching for the exception, I relized the problem was a bit different than the solutions I had seen. Instead, the Windows 7 Beta seems to do something very interesting with files moved between environments.

When files are moved to a Windows 7 Beta environment, they might be blocked to help protect the computer. I noticed this when I right-clicked on one of the Enterprise Library assemblies in my application and saw the following:

Here is what I did to get my project up and running again.

In order to solve the problem I did two things. First, I clicked the "Unblock" button. If you do not see an "Unblock" button, this means the file is already unblocked. Regardless, when I clicked the button, the previous text was grayed out as shown here:

To my surprise though, this did not entirely fix the problem. I then restarted IIS. This did not fix the problem. Finally, I resorted to restarting my machine. I'm guessing I need to restart the machine considering Windows 7 is in Beta at this point. Regardless, I am happy to announce that after restarting my machine, I was able to run my code again.

It is also important to recognize that all files the executing code touches may need to be unblocked. For instance, I had to unblock three different assemblies in order to get my code to actually work (I only needed to restart once though).

Do not let this post deter you from Windows 7. The Windows 7 Beta I am running is quite impressive. At first, I did not like the new taskbar. However, I can now say that I absolutely love it. I would defininately recommend giving the Windows 7 Beta a try.

1 comment:

Anonymous said...

Gah.. that blocking 'feature' is ANNOYING. It's distressing to hear that they've made it even more pervasive. I hope there's some way to turn it off!

Thanks for the heads up, btw. Definitely an important thing to be aware of for people trying Windows 7.