server:Windows server 2022 data center .
Sharepoint : SE.
使用VS2022 deploy之后,web页面访问SharePoint站点报缺失DLL的错误,这里边引入了NPOI库用来导入导出excel,但是导入的时候某些excel就会报错
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
但是自己项目引入的是6.0的这个DLL,为什么会找5.0的DLL呢,我尝试在站点的web.config直接添加bindingRedirect,发现有效果。
经过查阅资料可以用过一个VS内置工具来查看DLL查找错误的日志。
assembly binding log viewer (FUSLOGVW) Fuslogvw.exe (Assembly Binding Log Viewer) - .NET Framework | Microsoft Learn
The operation failed. Bind result: hr = 0x80131040. No description available. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable c:\windows\system32\inetsrv\w3wp.exe --- A detailed error log follows. === Pre-bind state information === LOG: DisplayName = System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified) LOG: Appbase = file:///C:/inetpub/wwwroot/wss/VirtualDirectories/9099/ LOG: Initial PrivatePath = C:\inetpub\wwwroot\wss\VirtualDirectories\9099\bin LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\ceaedf3a LOG: Cache Base = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\ceaedf3a LOG: AppName = bdf082ee Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\inetpub\wwwroot\wss\VirtualDirectories\9099\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: GAC Lookup was unsuccessful.
这里可以很详细的看到查找DLL的顺序,但是依然没有办法再部署的时候自动修改这个配置,我又查阅了相关的资料
发现Sharepoint在feature激活的时候使用SPWebConfiModification来修改web.config.
SPSecurity.RunWithElevatedPrivileges(() => { SPSite currentSite = properties.Feature.Parent as SPSite; var name = "*[local-name()='dependentAssembly'][*/@name='" + "System.Runtime.CompilerServices.Unsafe" + "'][*/@publicKeyToken='b03f5f7f11d50a3a'][*/@culture='neutral']"; var value = "<dependentAssembly><assemblyIdentity name='" + "System.Runtime.CompilerServices.Unsafe" + "' publicKeyToken='b03f5f7f11d50a3a' culture='neutral' /><bindingRedirect oldVersion='0.0.0.0-6.0.0.0' newVersion='6.0.0.0' /></dependentAssembly>"; SPWebConfigModification modification = new SPWebConfigModification() { Name = name, Path = "configuration/runtime/*[local-name()='assemblyBinding' and namespace-uri()='urn:schemas-microsoft-com:asm.v1']", Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode, Value = value, Sequence = 0, Owner = "SPAdmin" }; currentSite.WebApplication.WebConfigModifications.Add(modification); currentSite.WebApplication.Update(); currentSite.WebApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); });
标签:LOG,Sharepoint,DLL,wsp,file,NET,Microsoft,name From: https://www.cnblogs.com/lucky528/p/18394769