views:

820

answers:

2

Has anyone used WSP Builder to package a solution that uses the Config Store (http://www.codeplex.com/SPConfigStore) and deploys to the bin directory of the web application?

When I try to referecne the config store in my code behind file I get this exception...

System.Security.SecurityException: That assembly does not allow partially trusted callers

I've added the partially trusted callers attribute to my project

[assembly: AllowPartiallyTrustedCallers()]

and the sharepoint permissions attributes on my methods

[SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, Impersonate = true)] 
[SharePointPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, ObjectModel = true)]

But this hasn't seem to have done anything, I've also specified a custom CAS policy with the correct IPermission

<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" UnsafeSaveOnGet="True" Unrestricted="True" />

And still no success, surely other people have done this, I must be missing something

I'm using WSP Builder version 1.0.5.

A: 

Did you add the assembly to the web.config SafeControls section?

<SafeControl Assembly="Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.Server.Search.WebControls" TypeName="*" Safe="True" />

Also you may need to lower the trust level in the web.config:

<trust level="WSS_Minimal" originUrl="" />

See the MSDN docs for ASP.Net and SharePoint trust levels.

Moo
Yes safe control added. I'm not sure about lowering the trust level as I think that's the issue - if I set the trust level to full the code runs. However it's just my assembley that I want to have required permissions to run the code.
Rob
Have you signed the assembly at all?
Moo
Yes indeed, the WSPBuilder creates and sign the project automatically.
Rob
+1  A: 

You have added the [assembly: AllowPartiallyTrustedCallers()] to YOUR assembly, so your assembly WILL allow for partially trusted callers to call IT. But the ConfigStore itself does not have that attribute.

Is it possible to add your DLL to the GAC? (easy way out). Or add the [assembly: AllowPartiallyTrustedCallers()] to the ConfigStore project as well..

Colin
Does the ConfigStore need that attribute if it's in the GAC? I thought all assemblies in the GAC where fully trusted. The ConfigStore source code is available so that's a possibility.
Rob
When an assembly is in the GAC, it itself is automatically fully trusted. That doesn't mean it allows calls from partially trusted assemblies. I think...
Colin