views:

1851

answers:

5

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.

+1  A: 

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" />
Johan Leino
WSPBuilder has added this automatically; i've checked the web.config and is there.
Rob
A: 

Are you calling a third party assembly?

I ran into a situation recently that I was using a third party assembly and it did not have AllowPartiallyTrustedCallers in its code. When I tried to use the assebmly, it would fail.

hobbyman
It does use a third party assembley, but that is installed into the GAC.
Rob
Mine was also installed to the GAC but I still got the error.
hobbyman
so your saying that the third party assembly needs this attribute? For info the third party is http://spconfigstore.codeplex.com/I can use this third party without problems if I create my own manual CAS policy (it uses exaclty the same code). It just seems to be a problem using WSPBuilder, I can't seem to find the correct permission set to add.
Rob
I think you can have custom CAS policy while using WSPBuilder. I remember seeing something about it. Bad thing about WSPBuilder is that there isn't much documentation but I love it.
hobbyman
It seems the CAS policy WSPBuilder creates contains the correct IPermissions but this CAS policy is based on WSS_Minimum, which doesn't have the required Security Class in the first place. I tried basing it on WSS_Medium but didn't have much luck.
Rob
A: 

Are you sure that the assembly has been deployed to bin and no to GAC by accident? If there are two assemblies the one in GAC takes precedence.

Waldek Mastykarz - MOSS MVP
I checked this and there is no dll on the GAG, just the bin folder.
Rob
+1  A: 

Never seen this.. but I suspect not many people have created codebehinds to the master pages in SharePoint (Microsoft doesn't too!).

I don't know what you are trying to build but I'd probably implement it using a server control that is included on the master page.

AllowPartiallyTrustedCallers has always fixed it for my server controls.

What is the trust in your web.config file set to? Try Full.

ArjanP
I think you may be right about using a server control as I think they run in full trust (which seems to be the issue).
Rob
A: 

You might try checking that you are using the fully qualified five part name including the correct public key token and namespace for your assemblies.

Junx