1

I installed MVC3 from the nuget package manager and everything seems to be compiling ok but when I try to run my application I am getting the following:

System.TypeLoadException was unhandled by user code
  HResult=-2146233054
  Message=Inheritance security rules violated by type: 'Ninject.Web.Mvc.Filter.FilterContextParameter'. Derived types must either match the security accessibility of the base type or be less accessible.
  Source=mscorlib
  TypeName=Ninject.Web.Mvc.Filter.FilterContextParameter
  StackTrace:
       at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
       at System.Reflection.RuntimeAssembly.GetExportedTypes()
       at Ninject.Infrastructure.Language.ExtensionsForAssembly.HasNinjectModules(Assembly assembly) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForAssembly.cs:line 25
       at Ninject.Modules.CompiledModuleLoaderPlugin.<LoadModules>b__0(Assembly asm) in c:\Projects\Ninject\ninject\src\Ninject\Modules\CompiledModuleLoaderPlugin.cs:line 81
       at Ninject.Modules.AssemblyNameRetriever.AssemblyChecker.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter) in c:\Projects\Ninject\ninject\src\Ninject\Modules\AssemblyNameRetriever.cs:line 114
       at Ninject.Modules.AssemblyNameRetriever.AssemblyChecker.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter)
       at Ninject.Modules.AssemblyNameRetriever.GetAssemblyNames(IEnumerable`1 filenames, Predicate`1 filter) in c:\Projects\Ninject\ninject\src\Ninject\Modules\AssemblyNameRetriever.cs:line 54
       at Ninject.Modules.CompiledModuleLoaderPlugin.LoadModules(IEnumerable`1 filenames) in c:\Projects\Ninject\ninject\src\Ninject\Modules\CompiledModuleLoaderPlugin.cs:line 81
       at Ninject.Modules.ModuleLoader.LoadModules(IEnumerable`1 patterns) in c:\Projects\Ninject\ninject\src\Ninject\Modules\ModuleLoader.cs:line 60
       at Ninject.KernelBase.Load(IEnumerable`1 filePatterns) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 236
       at Ninject.KernelBase..ctor(IComponentContainer components, INinjectSettings settings, INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 97
       at Ninject.KernelBase..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 57
       at Ninject.StandardKernel..ctor(INinjectModule[] modules) in c:\Projects\Ninject\ninject\src\Ninject\StandardKernel.cs:line 46
       at HoneyBadger.Web.Mvc.App_Start.NinjectWebCommon.CreateKernel() in c:\HoneyBadger\trunk\HoneyBadger.Web.Mvc\HoneyBadger.Web.Mvc\App_Start\NinjectWebCommon.cs:line 43
       at Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\Bootstrapper.cs:line 50
       at HoneyBadger.Web.Mvc.App_Start.NinjectWebCommon.Start() in c:\HoneyBadger\trunk\HoneyBadger.Web.Mvc\HoneyBadger.Web.Mvc\App_Start\NinjectWebCommon.cs:line 26
  InnerException: 

Any ideas??

Updated:

I also wanted to add that it is bombing on the new StandardKernel()

private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

            RegisterServices(kernel);

            return kernel;
        }

New error being presented after adding the AllowPartiallyTrustedCallers:

Attempt by security transparent method 'HoneyBadger.Web.Mvc.App_Start.NinjectWebCommon..cctor()' to access security critical method 'Ninject.Web.Common.Bootstrapper..ctor()' failed.

Assembly 'HoneyBadger.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 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.
spyter
  • 727
  • 1
  • 9
  • 25

1 Answers1

0

After doing some research online, one thing I found is that you need to AllowPartiallyTrustedCallers for your assembly:

[assembly: AllowPartiallyTrustedCallers]

Does your project have that enabled?

More links:

Community
  • 1
  • 1
Damian Schenkelman
  • 3,505
  • 1
  • 15
  • 19
  • That got me passed the original error but now it presented a new one (see my original post, i updated it) – spyter Oct 02 '12 at 12:05
  • NOTE: i also tried changing sec level to one via [assembly: SecurityRules(SecurityRuleSet.Level1)] with no luck.. :/ – spyter Oct 02 '12 at 12:07
  • Hmmm it seems there are a lot of issues in the web related to similar issues: https://groups.google.com/forum/#!topic/ninject/xInlcd2b1l8/discussion http://stackoverflow.com/questions/7494298/ninject-mockingkernel-moq-security-exception https://github.com/ninject/ninject.web.mvc/issues/15 (this last one says medium trust issues have not been solved in their MVC 3 version) – Damian Schenkelman Oct 02 '12 at 14:38