I am working on a sandboxed solution SharePoint 2010 (SharePoint Online project).
The error I get is
Error 19 Error occurred in deployment step 'Add Solution': This solution contains invalid markup or elements that cannot be deployed as part of a sandboxed solution. Solution manifest for solution 'c353c02e-f7b0-4c58-b7c6-066adf1d7e0c' failed validation, file manifest.xml, line 3, character 4: The element 'Solution' in namespace 'http://schemas.microsoft.com/sharepoint/' has invalid child element 'CodeAccessSecurity' in namespace 'http://schemas.microsoft.com/sharepoint/'. List of possible elements expected: 'FeatureManifests, Assemblies, ActivationDependencies' in namespace 'http://schemas.microsoft.com/sharepoint/'.
0 0 Starwood_Forms
My manifest file (Package.package) in Visual Studio looks like this
<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="c353c02e-f7b0-4c58-b7c6-066adf1d7e0c" SharePointProductVersion="14.0">
<CodeAccessSecurity>
<PolicyItem>
<PermissionSet class="NamedPermissionSet" version="1" Description="Permission set for ProjectNameHere.">
<IPermission class="AspNetHostingPermission" version="1" Level="Minimal" />
<IPermission class="SecurityPermission" version="1" Flags="Execution,ControlPrincipal,ControlAppDomain,ControlDomainPolicy,ControlEvidence,ControlThread" />
<IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="UserName" />
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
</PermissionSet>
<Assemblies>
<Assembly Name="ProjectNameHere" />
</Assemblies>
</PolicyItem>
</CodeAccessSecurity>
<Assemblies>
<Assembly Location="ProjectNameHere.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="ProjectNameHere, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7e39ecec9e69afb4" Namespace="ProjectNameHereWebPart" TypeName="*" />
</SafeControls>
</Assembly>
</Assemblies>
<FeatureManifests>
<FeatureManifest Location="ProjectNameHere_Feature2\Feature.xml" />
</FeatureManifests>
</Solution>
If I remove "CodeAccessSecurity" tag from the "Solution" element then the solution is deployed and activated from VS without any issues. I am unable to activate the solution from the web, I tried.
The solution contains one Web Part which uses LINQ to get data from other lists + create a new list item in a list.
I addedd the "CodeAccessSecurity" tag in "Solution" because without it I got an error
The type initializer for 'Microsoft.SharePoint.Linq.Resources' threw an exception.
Error Source: Microsoft.SharePoint.Linq
Stack Trace: at Microsoft.SharePoint.Linq.Resources.GetString(String resourceId, Object[] args)
at Microsoft.SharePoint.Linq.EntityTracker.ProcessAssociatedEntity(NewEntityRef newEref, Stack`1 visited, PropertyMap pm, Object lookupEntity)
at Microsoft.SharePoint.Linq.EntityTracker.ProcessAssociatedEntities(NewEntityRef newEref, ITrackOriginalValues origVals, Stack`1 visited)
at Microsoft.SharePoint.Linq.EntityTracker.SubmitNewEntity(NewEntityRef newEref, Stack`1 visited)
at Microsoft.SharePoint.Linq.EntityTracker.SubmitNewEntities()
at Microsoft.SharePoint.Linq.EntityTracker.SubmitChanges(ConflictMode failureMode, Boolean systemUpdate)
at Microsoft.SharePoint.Linq.DataContext.SubmitChanges(ConflictMode failureMode, Boolean systemUpdate)
at Microsoft.SharePoint.Linq.DataContext.SubmitChanges()
at Starwood.Forms.TaskForceNeedWebPart.TaskForceNeedWebPart.btnSubmit_Submit(Object sender, EventArgs e)
Target Site: System.String GetString(System.String, System.Object[])
Help Link:
Data Begin Information
Data End Information
Writing inner exception details.
Error Message: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Error Source: mscorlib
Stack Trace: at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Reflection.Assembly.VerifyCodeBaseDiscovery(String codeBase)
at System.Reflection.Assembly.GetName(Boolean copiedName)
at Microsoft.SharePoint.Linq.Resources.GetResourceManager()
at Microsoft.SharePoint.Linq.Resources..cctor()
Target Site: Void Check(System.Object, System.Threading.StackCrawlMark ByRef, Boolean)
Help Link:
Data Begin Information
Data End Information
I get the above error when the code is tryin to create a new list item.
I am using sandboxed visual web part.
The solution is activated without any issues if I remove "CodeAccessSecurity" child element from "Solution" but I am not able to create a new list item. I am using LINQ to SharePoint to create a new list item