C# read json file throw exception: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1

Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, 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)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, 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)

 

 

 

昨天为旧系统添加一些功能,程序已经修改与测试好,更新至服务器,用户运行程序时,页面却抛出异常,异常内容如上。
奇了,开发本机运行没有问题呀,为何更新至服务器却有问题。是不是漏上传什么文件? 花上很长时间一一对比。文件数量均对等。
......

问题没有解决,不死心,今早打开程序,第一眼看到的是.web.config文档,打开来与服务器端的web.config对比看,哇,终于发现两个文件代码不相同。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-6.0.1.0" newVersion="6.0.1.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Source Code


程序抛出的异常终于解决。

想想问题的出现,原来开发程序时,Insus.NET有使用NuGet添加System.Text.Json dll class library,并在程序中,引用这个类库时,它有对本机的web.config自动添加内容。

 

posted @ 2024-11-15 10:43  Insus.NET  阅读(25)  评论(0编辑  收藏  举报