2012-08-14 110 views
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中部署和激活,不會有任何問題。我無法從網絡激活解決方案,我試過了。

該解決方案包含一個使用LINQ從其他列表中獲取數據的Web部件+在列表中創建一個新的列表項。

我addedd的「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到SharePoint以創建一個新的列表項

回答

0

如果我不使用的數據上下文來創建新的列表項然後將以下代碼工作完美

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

         newListItem.Update(); 

如果您有任何其他想法,請讓我知道