R – WSPBuilder and Code behind for a Sharepoint Masterpage

mosssharepointwspbuilderwss

I created a code behind file for a custom master page in visual studio. I hooked everything up manually; safe control and custom cas policy. Everything works great!

I then wanted to put this into a sharepoint solution using WSPBuilder for better deployment. I created WSP solution, added my class file and changed the output directory to the bin folder. I then built the solution and deployed it, making sure to change the page directives on the master page to reflect the new assembly name.

Now when I go to view the sharepoint site I get an error stating Security Exception error stating

‘Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.’

This has me stumped as it works as a visual studio class file deployed to the bin directory of the website.
However when I put this into a sharepoint solution it breaks! I tried adding

‘[assembly: System.Security.AllowPartiallyTrustedCallers]’

to the AssemblyInfo.cs but this hasn’t helped.

Anyone else experinced this or have any advice?

EDIT: I should also mention that the code behind is trying to access a sharepoint list.

Best Answer

Don´t you still have to include the SafeControls entry in order for it to work, like:

<SafeControl Assembly="[FullAssembly Name]"
                     Namespace="[YourMasterPageNamespace]"
                     TypeName="*"
                     Safe="True" />

or in WSPBuilder config:

<add key="BuildSafeControls" value="True" />