尝试使用Mvc3和Ninject时出错

时间:2012-10-02 00:25:23

标签: c# asp.net-mvc ninject

我从nuget包管理器安装了MVC3,一切似乎都在编译好但是当我尝试运行我的应用程序时,我得到以下内容:

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: 

任何想法?

更新:

我还想补充说它是对新的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;
        }

添加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.

1 个答案:

答案 0 :(得分:0)

完成some research online后,我发现有一件事是你需要AllowPartiallyTrustedCallers来组装:

[assembly: AllowPartiallyTrustedCallers]

您的项目是否已启用?

更多链接: