C#Unity错误:无法加载文件或程序集

C# Unity Error: Could not load file or assembly(C#Unity错误:无法加载文件或程序集)

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

问题描述

我在Unity上找到了这篇演示文章。看起来非常简单,但我收到以下错误:

无法加载文件或程序集 ‘System.Rounme.CompilerServices.Unsafe,Version=4.0.4.1, 区域性=中性,PublicKeyToken=b03f5f7f11d50a3a‘或其 从属关系。找到的程序集的清单定义不 匹配程序集引用。(HRESULT异常:0x80131040)

https://www.tutorialsteacher.com/ioc/register-and-resolve-in-unity-container

using System;
using Unity;

namespace UnityContainerDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            var container = new UnityContainer();
            container.RegisterType<ICar, BMW>();// Map ICar with BMW 

            //Resolves dependencies and returns Driver object 
            Driver drv = container.Resolve<Driver>();
            drv.RunCar();
        }
    }

    public interface ICar
    {
        int Run();
    }

    public class BMW : ICar
    {
        private int _miles = 0;

        public int Run()
        {
            return ++_miles;
        }
    }

    public class Ford : ICar
    {
        private int _miles = 0;

        public int Run()
        {
            return ++_miles;
        }
    }

    public class Audi : ICar
    {
        private int _miles = 0;

        public int Run()
        {
            return ++_miles;
        }

    }
    public class Driver
    {
        private ICar _car = null;

        public Driver(ICar car)
        {
            _car = car;
        }

        public void RunCar()
        {
            Console.WriteLine("Running {0} - {1} mile ", _car.GetType().Name, _car.Run());
        }
    }
}

推荐答案

当我尝试复制该问题时,运行了System.Runtime.CompilerServices.Unsafe的NuGet更新后,错误消失了。

这篇关于C#Unity错误:无法加载文件或程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:C#Unity错误:无法加载文件或程序集

基础教程推荐