部署步骤添加解决方案时出错

时间:2012-08-14 21:24:19

标签: sharepoint-2010 sandbox-solution

我正在开发一个沙盒解决方案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>

如果我删除&#34; CodeAccessSecurity&#34;标签来自&#34;解决方案&#34;然后,从VS部署并激活解决方案,没有任何问题。我无法通过网络激活解决方案,我试过了。

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

我添加了&#34; CodeAccessSecurity&#34;标签&#34;解决方案&#34;因为没有它我得到了一个错误

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 

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

我正在使用沙盒可视化网络部分。

如果我删除&#34; CodeAccessSecurity&#34;解决方案被激活而没有任何问题。来自&#34;解决方案&#34;的子元素但我无法创建新的列表项。我正在使用LINQ to SharePoint来创建新的列表项

1 个答案:

答案 0 :(得分:0)

如果我不使用数据上下文创建新列表项,则以下代码可以正常运行

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

                        newListItem.Update();

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