无法加载文件或程序集System.Runtime.CompilerServices.Unsafe [英] Could not load file or assembly System.Runtime.CompilerServices.Unsafe

查看:177
本文介绍了无法加载文件或程序集System.Runtime.CompilerServices.Unsafe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ServiceStack.Redis 用C#创建了一个Visual Studio(社区2019)项目.由于它是C#,因此我使用Windows 10(有Windows的Redis版本,但是它确实很旧,而且据我所知,它是非官方的,所以我担心这可能是问题所在).这是我的代码的摘录:

I created a Visual Studio (Community 2019) project with C# using ServiceStack.Redis. Since it is C#, I use Windows 10 (there is a Redis version for Windows but it is really old and as I know, it is unofficial so I am afraid that might be the problem). Here is an excerpt from my code:

public class PeopleStorage: IDisposable
{
    public PeopleStorage()
    {
        redisManager = new RedisManagerPool("localhost");
        redis = (RedisClient)redisManager.GetClient();
        facts = (RedisTypedClient<List<Fact>>)redis.As<List<Fact>>();
    }

    public List<Fact> GetFacts(int id)
    {
        string sid = id.ToString();
        if (facts.ContainsKey(sid))
            return facts[sid];
        return accessor.GetFacts(id);
    }

    private RedisTypedClient<List<Fact>> facts;
    private RedisClient redis;
    private RedisManagerPool redisManager;
}

试图在行 return facts [sid]; 中连接到Redis,发生异常:

In an attempt to connect to Redis in line return facts[sid];, an exception occurs:

System.IO.FileLoadException:无法加载文件或程序集"System.Runtime.CompilerServices.Unsafe,版本= 4.0.4.1,文化=中性,PublicKeyToken = b03f5f7f11d50a3a"或其中之一依赖.找到的程序集的清单定义不匹配大会参考.(来自HRESULT的异常:0x80131040)"

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 it's dependences. The found Assembly's manifest definition does not match the Assembly reference. (Exception from HRESULT: 0x80131040)"

(我翻译的可能不准确)

(May be inaccurate as I have translated it)

我尝试更新所有软件包,从 ServiceStack 软件包开始,以 System.Runtime.CompilerServices.Unsafe 本身结束.此外,您不能在NuGet中选择4.0.4.1版本,最接近的版本是4.0.0,而相关的版本是4.0.7.

I have tried updating all the packages, starting with ServiceStack packages, ending with System.Runtime.CompilerServices.Unsafe itself. Moreover, you can't choose 4.0.4.1 version in NuGet, the closest one there is 4.0.0, while the relevant is 4.0.7.

我不明白为什么要使用此版本以及如何解决此问题.
即使重新安装Visual Studio也无济于事.

I do not understand why it uses this version and how I can fix this problem.
Even a clean reinstall of Visual Studio did not help.

推荐答案

无法加载文件或程序集System.Runtime.CompilerServices.Unsafe

Could not load file or assembly System.Runtime.CompilerServices.Unsafe

似乎您已经安装了 System.Runtime.CompilerServices.不安全 nuget软件包 4.5.3 版本.它对应于 System.Runtime.CompilerServices.Unsafe.dll 程序集版本 4.0.4.1 .

It seems that you have installed System.Runtime.CompilerServices.Unsafe nuget package 4.5.3 version. And it corresponds to System.Runtime.CompilerServices.Unsafe.dll assembly version 4.0.4.1.

建议

1)请尝试将 System.Runtime.CompilerServices.Unsafe 版本 4.0.4.1 注册到GAC中,以便系统可以使用它.

1) Please try to register System.Runtime.CompilerServices.Unsafe version 4.0.4.1 into GAC so that the system can it.

  • 管理员

类型:

cd xxxxx (the path of the the System.Runtime.CompilerServices.Unsafe 4.0.4.1)

gacutil /i System.Runtime.CompilerServices.Unsafe.dll

2)如果您将Net Framework项目与 xxx.config 文件一起使用,则可以使用

2) If you use Net Framework projects with xxx.config file, you could use bindingRedirect.

将它们添加到 app.config 文件或 web.config 文件中:

Add these in app.config file or web.config file:

<configuration>  
   <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-4.0.4.1"  
                             newVersion="4.0.4.1"/>  
         </dependentAssembly>  
      </assemblyBinding>  
   </runtime>  
</configuration> 

此外,如果将 System.Runtime.CompilerServices.Unsafe nuget软件包版本更新为较新的版本,则还应该更改bindingRedirect程序集版本.

Besides, if you update System.Runtime.CompilerServices.Unsafe nuget package version to the newer version, you should also changed the bindingRedirect assembly version.

您可以引用以下这些程序集版本的 System.Runtime.CompilerServices.Unsafe

You can refer to these assembly versions of System.Runtime.CompilerServices.Unsafe

4.5.x System.Runtime.CompilerServices.Unsafe nuget软件包版本,而 4.0.xx System.Runtime.CompilerServices.Unsafe.dll 程序集版本.

4.5.x is System.Runtime.CompilerServices.Unsafe nuget package version while 4.0.x.x is System.Runtime.CompilerServices.Unsafe.dll assembly version.

4.5.0 is 4.0.4.0 
4.5.1 is 4.0.4.0 
4.5.2 is 4.0.4.0 
4.5.3 is 4.0.4.1
4.6.0 is 4.0.5.0
4.7.0 is 4.0.6.0
4.7.1 is 4.0.6.1

这篇关于无法加载文件或程序集System.Runtime.CompilerServices.Unsafe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆