Skip to content

Loading…

Assembly failing to load with security warnings #4

Closed
vincpa opened this Issue · 5 comments

4 participants

@vincpa

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

            Bind<LoggedControllerFactory>()
                .ToSelf()
                .InSingletonScope();
        }
    }

    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;
        }
    }

///Ninject.MVC3.cs
private static void RegisterServices(IKernel kernel)
        {
            kernel.Load(Assembly.GetExecutingAssembly());

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

            ControllerBuilder.Current.SetControllerFactory(factory);
        }  

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=2.2.0.0, 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?

@ChrisMH

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.

@remogloor
Ninject member

Will be fixed for 2.4

@rdefreitas

Any update on release for this fix?

@remogloor
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.

@remogloor
Ninject member

Fixed

@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.