ninjectmscorlib

'Could not load type 'System.Runtime.Remoting.RemotingServices' from assembly 'mscorlib in Ninject


I have a problem as stated at the title. I am using Ninject as a Dependency Injection and my Service Locator as below:

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();

        }

    }
}

I have used ServiceLocator in my class ErrorService class as below:

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>();


    }

}

I have got the System.TypeLoadException at the line

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

'Could not load type 'System.Runtime.Remoting.RemotingServices' from assembly 'mscorlib,


Solution

  • After investigation, I have pointed out that my test project type was MsTest Test Project. (.Net Core) When I choose unit test project (.NET Framework) the problem has solved.