I have created a visual web part in Visual Studio 2010 which is to be deployed to the /bin directory of our SharePoint web applications. The idea being we can have a development, staging, UAT web application each using their own version of the web parts.

As it is to be deployed to the /bin directory I have edited the package xml to include CAS details

<PermissionSet class="NamedPermissionSet" version="1">
  <IPermission class="SecurityPermission" version="1" Flags="Execution"/>
  <IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
  <IPermission class="WebPartPermission" version="1" Connections="True" />
  <IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
  <Assembly Name="$SharePoint.Project.AssemblyName$" Version="$SharePoint.Project.AssemblyVersion$" PublicKeyBlob="$SharePoint.Project.AssemblyPublicKeyBlob$"/>

Note that I've also tried setting the Level to Medium on the AspNetHostingPermission line.

If I deploy this from Visual Studio, I can see the web part listed but I get an error when adding the part to the page. From various tinkering around I have had two messages:-

The file '/_CONTROLTEMPLATES/xxxxx/MyWebPart.ascx' does not exist


Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

This makes me think there is a problem with my CAS policy, but I'm at a lost to determine the error. Does anybody have any pointers for me?

  • Is it a Sandbox solution ? You can't use Visual webpart from within them... Mar 15, 2011 at 17:34
  • No, Sandboxed Solution is set to false. Probably also worth mentioning that Assembly Deployement is set to WebApplication and that I have confirmed that the dll is located in the correct web application bin directory (rather than the GAC) and tha the ascx file is in the control templates sub folder.
    – grimorde
    Mar 16, 2011 at 8:42
  • You do realise you have no IPermission node for FileIOPermission? That's what the error you get is complaining about.
    – James Love
    Mar 28, 2011 at 13:52
  • As I mentioned in reply to Elena's comment below, I did try adding the FileIOPermission in the CAS file with no effect.
    – grimorde
    Mar 31, 2011 at 13:08

2 Answers 2


Have you tried adding FileIOPermission to the webpart cs file (sample below) in CreateChildControls as there the user control is instantiated from its location on the File system, hence the requirement for FileIOPermission

 [SharePointPermission(SecurityAction.Demand, ObjectModel = true), FileIOPermission(SecurityAction.Demand, Unrestricted = true)]
protected override void CreateChildControls()
  • Actually, no I didn't try that. I did try adding the FileIOPermissions in the CAS file to no effect. Not sure if that's the same or not....
    – grimorde
    Mar 28, 2011 at 13:40

I've ended up downloading the SharePoint Power Tools for Visual Studio. That allowed me to create a Sandbox Visual Web Part and has resolved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.