.Net Standard 2.0 with .Net Framework 4.8 - 无法加载文件或程序集 System.Security.Principal.Windows, Version=4.1.1.0

问题描述

我正在开发用 .Net Framework 4.8 编写的 ASP 应用程序,在 Windows Server 2012 R2 上的 IIS 上运行。我创建了一个 NuGet 包,它是一个 .Net Standard 2.0 库,它通过 Visual Studio 调试在我的本地机器上愉快地运行。

将其部署到服务器后(用新的 bin 文件夹替换了现有的 bin 文件夹,包括所有新文件),我现在收到此错误

Could not load file or assembly 'System.Security.Principal.Windows,Version=4.1.1.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest deFinition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我正在运行最新版本的 MS Build Tools、可用于服务器的最新 Windows 更新,并且 .Net Framework 应用程序和 .Net Standard 库都使用 System.Security 的第 5 版。 Principal.Windows,尽管此错误消息说的是什么。

我已确保在服务器上启用了与 IIS 相关的所有 Windows 功能,就像它们在我的开发机器上一样。我已经重建了应用程序和库。我已经完全卸载并重新安装了 System.Security.Principal.Windows NuGet 包。我已经尝试在应用程序的 csproj 文件中设置它:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType

我也试过在 csproj 中设置:

<PropertyGroup>
    <!--- ... -->
    <RestoreProjectStyle>packagereference</RestoreProjectStyle>
    <!--- ... -->
</PropertyGroup>  

到目前为止没有任何效果。鉴于它在我的本地机器上运行完美,我不清楚为什么这会是一个问题。

有什么建议吗? Stack Overflow 上针对其他类似问题提供的解决方案对我不起作用。

解决方法

对此的解决方案是在应用程序项目和库项目上安装 NuGet 包,特别是 <html> <head> <title>ضمور العضلات</title> <style> .img-container { text-align: center; } </style> <!-- Font Awesome --> </head> <audio id="musicSound" preload="auto" src="disability/sounds/song.mp3" > </audio> <audio id="hungrySound" preload="auto" src="disability/sounds/water.mp3" > </audio> <body style="background: #E8E8E8;"> <div class="container"> <div class="row" style="margin-top: 30px;"> <div class="col-md"> <img id="thirsty" onmouseover="playHungry()" src="disability/images/hungry_icon.png" class="img-thumbnail" title="أنا جائع"> </div> </div> <div class="row" style="margin-top: 130px;"> <div class="col-md" > <img id="music" onmouseover="playMusic()" src="disability/images/music_icons.png" class="img-thumbnail" title="شغل الموسيقى"> </div> </div> </div> <script> var music = document.getElementById("musicSound"); var hungry= document.getElementById("hungrySound"); function playMusic() { music.play(); thirsty.pause(); thirsty.currentTime = 0; } function playHungry() { hungry.play(); music.pause(); music.currentTime = 0; } </script> </body> </html> ,它用于使用包中包含的 C# 和 Visual Basic 编译器构建项目,而不是随 MSBuild 安装的版本。

虽然此软件包现已弃用,但鉴于应用程序使用 .Net Framework 而不是 .Net Core 2.1+ 运行,它是正确的使用版本。