«Не удалось загрузить тип «System.Runtime.Remoting.RemotingServices» из сборки «mscorlib в Ninject».

У меня проблема, как указано в заголовке. Я использую Ninject в качестве инъекции зависимостей и свой локатор сервисов, как показано ниже:

internal class ServiceLocator
{
    private static readonly IServiceLocator _serviceLocator;

    static ServiceLocator()
    {
        _serviceLocator = new DefaultServiceLocator();
    }

    public static IServiceLocator Current
    {
        get
        {
            return _serviceLocator;
        }
    }

    private class DefaultServiceLocator : IServiceLocator
    {
        private readonly IKernel kernel;  // Ninject kernel

        public DefaultServiceLocator()
        {
            kernel = new StandardKernel();
            LoadBindings();
        }

        public T Get<T>()
        {

            try
            {
                return kernel.Get<T>();
            }
            catch (Exception hata)
            {
                throw hata;
            }

        }

        private void LoadBindings()
        {
            kernel.Bind<IErrorDal>().To<ErrorDal>().InSingletonScope().WithConstructorArgument("connectionString", "myConnectionString");
            kernel.Bind<IErrorBusinessRule>().To<ErrorBusinessRule>().InSingletonScope();
            kernel.Bind<IApplicationBusinessRule>().To<ApplicationBusinessRule>().InSingletonScope();
            kernel.Bind<ControlService>().To<ControlService>().InSingletonScope();

        }

    }
}

Я использовал ServiceLocator в своем классе ErrorService, как показано ниже:

public class ErrorService : IErrorService
{

    private readonly IErrorBusinessRule _errorBusinessRule;

    private readonly IApplicationBusinessRule _applicationBusinessRule;

    private readonly ControlService _controlService;        

    public ErrorService()
    {         
        //I am getting the error here.
        this._errorBusinessRule = ServiceLocator.Current.Get<IErrorBusinessRule>();
        this._controlService = ServiceLocator.Current.Get<ControlService>();
        this._uygulamaIsKurali = ServiceLocator.Current.Get<IApplicationBusinessRule>();


    }

}

У меня есть System.TypeLoadException в строке

this._errorBusinessRule = ServiceLocator.Current.Get();

«Не удалось загрузить тип «System.Runtime.Remoting.RemotingServices» из сборки «mscorlib,


person tahasozgen    schedule 01.08.2019    source источник


Ответы (1)


После расследования я указал, что тип моего тестового проекта был MsTest Test Project. (.Net Core) Когда я выбираю проект модульного тестирования (.NET Framework), проблема решена.

person tahasozgen    schedule 01.08.2019