Assembly failing to load with security warnings #4

Closed
vincpa opened this Issue May 31, 2011 · 5 comments

Comments

Projects
None yet
4 participants
@vincpa

vincpa commented May 31, 2011

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

This comment has been minimized.

Show comment
Hide comment
@ChrisMH

ChrisMH Jun 7, 2011

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.

ChrisMH commented Jun 7, 2011

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

This comment has been minimized.

Show comment
Hide comment
@remogloor

remogloor Jun 11, 2011

Member

Will be fixed for 2.4

Member

remogloor commented Jun 11, 2011

Will be fixed for 2.4

@rdefreitas

This comment has been minimized.

Show comment
Hide comment
@rdefreitas

rdefreitas Aug 22, 2011

Any update on release for this fix?

Any update on release for this fix?

@remogloor

This comment has been minimized.

Show comment
Hide comment
@remogloor

remogloor Aug 24, 2011

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.

Member

remogloor commented Aug 24, 2011

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

This comment has been minimized.

Show comment
Hide comment
@remogloor

remogloor Oct 12, 2011

Member

Fixed

Member

remogloor commented Oct 12, 2011

Fixed

@remogloor remogloor closed this Oct 12, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment