1

我正在开发沙盒解决方案 SharePoint 2010(SharePoint Online 项目)。

我得到的错误是

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

我在 Visual Studio 中的清单文件(Package.package)看起来像这样

<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>

如果我从“解决方案”元素中删除“CodeAccessSecurity”标签,则解决方案将从 VS 部署和激活,没有任何问题。我无法从网络激活解决方案,我试过了。

该解决方案包含一个 Web 部件,它使用 LINQ 从其他列表中获取数据 + 在列表中创建一个新的列表项。

我在“解决方案”中添加了“CodeAccessSecurity”标签,因为没有它我得到一个错误

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 

当代码尝试创建新列表项时,我收到上述错误。

我正在使用沙盒可视化 Web 部件。

如果我从“解决方案”中删除“CodeAccessSecurity”子元素但我无法创建新的列表项,则该解决方案被激活,没有任何问题。我正在使用 LINQ to SharePoint 创建一个新的列表项

4

1 回答 1

0

如果我不使用数据上下文来创建新的列表项,那么以下代码可以完美运行

 SPList list = objWeb.Lists.TryGetList("ListName");
                        SPListItem newListItem = list.AddItem();
                        newListItem["Department"] = new SPFieldLookupValue(int.Parse(ddlDepartment.SelectedValue), ddlDepartment.SelectedItem.Text);

                        newListItem.Update();

如果您有任何其他想法,请告诉我

于 2012-08-15T14:21:12.490 回答