Tuesday, June 2, 2009

That assembly does not allow partially trusted callers.

So I ran into something to be aware of today. We have a couple of Custom Field Types that we have written. As with all SharePoint CFTs, their assemblies are deployed to the GAC.

Today I was writing a Control (a Web Part would apply here just the same) that is deployed to the Bin. While deploying it I kept getting the annoying error: "That assembly does not allow partially trusted callers". I had my CAS policies defined and had the '[assembly: System.Security.AllowPartiallyTrustedCallers]' attribute in my AssemblyInfo.cs but I realized that I was getting the exception when I was trying to access the field value of an item that contained my Custom Field Type column (item["my CFT"])!

This was a good reminder that all CFTs should have the [assembly: System.Security.AllowPartiallyTrustedCallers] attribute, just in case, since you never know when a Web Part or some other partially trusted code will need to access them in the future.

No comments: