Skip to content


Assembly failing to load with security warnings #4

vincpa opened this Issue · 5 comments

4 participants


Started a brand new MVC3 web app project

Used NuGet to install

  • NinjectMVC3 -NLog -Ninject.Extensions.Logging.NLog2

Created a new controller factory and new NinjectModule

public class ApplicationModule : NinjectModule {

        public override void Load() {


    class LoggedControllerFactory : DefaultControllerFactory {

        ILogger Logger { get; set; }

        public LoggedControllerFactory(ILogger logger) {

            Logger = logger;

            Logger.Trace("Created controller factory instance");

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) {

            Logger.Trace("Attempting to create controller instance");

            IController c = base.GetControllerInstance(requestContext, controllerType);

            Logger.Trace("Created controller instance {0}", controllerType.ToString());

            return c;

private static void RegisterServices(IKernel kernel)

            IControllerFactory factory = kernel.Get<LoggedControllerFactory>();


Got this error when running the application.

Attempt by security transparent method 'Ninject.Extensions.Logging.NLog2.Infrastructure.NLogLogger..ctor(System.Type)' to access security critical method 'NLog.LogManager.GetLogger(System.String)' failed.

Assembly 'Ninject.Extensions.Logging.NLog2, Version=, Culture=neutral, PublicKeyToken=c7192dc5380945e7' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.

Am I missing something?


I'm having the same issue.

It happens both in an MVC3 web application and in a WPF desktop application.

I cloned all the source and removed the 'AllowPartiallyTrustedCallers' attributes in all of the Ninject AssemblyInfo.cs files, recompiled, and all worked fine.

Guess I'll have to read up on the new .NET 4.0 security policies.

Ninject member

Will be fixed for 2.4


Any update on release for this fix?

Ninject member

Sorry I can't give any timeline because I have no idea how much time I can spend on Ninject. But because it is open source you can always speed up by contributing a patch.

Ninject member


@remogloor remogloor closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.