Running Ninject 3 on medium trust level

点点圈 提交于 2019-12-13 01:29:07

问题


I've an ASP.NET MVC3 application with Ninject 3. The Ninject 3 was installed using NuGet, and now I'm trying to publish this application on a host that uses medium trust level.

So after I searched on google a little I found an build on the Ninject GoogleCode project website an specific version for medium trust environments, so I downloaded and changed the references on my project, and after I published it I still get the same error.

I already changed the way that I create my kernel and I'm using:

var kernel = new StandardKernel(new NinjectSettings { UseReflectionBasedInjection = true });

And I still get the error.

So anyone already faced this issue and solved it?


回答1:


Try this:

Open this file: MyProjectName\Properties\ AssemblyInfo.cs and then add this line

[assembly: AllowPartiallyTrustedCallers]

In the Global.asax :

     INinjectSettings settings = new NinjectSettings
        {
            UseReflectionBasedInjection = true,    // disable code generation for partial trust
            InjectNonPublic = false,               // disable private reflection for partial trust
            InjectParentPrivateProperties = false, // reduce magic
            LoadExtensions = false                 // reduce magic
        };

        IKernel kernel = new StandardKernel(settings);


来源:https://stackoverflow.com/questions/11989300/running-ninject-3-on-medium-trust-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!