2012-10-02 28 views
1

我從NuGet包管理器安裝MVC3,一切似乎是編譯好的,但是當我嘗試運行我的應用我收到以下錯誤:獲得當試圖使用MVC3和Ninject

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. 
+0

什麼是內部異常?你是從一個標準的MVC網站運行嗎?你使用的是什麼版本的.NET? –

+0

.NET v4,MVC4和內部ex是空的 – spyter

+0

你有沒有得到這個地方?我正在將Ninject 2.2的MVC4項目升級到3.0,並獲得類似的問題。 – mackie

回答

0

後做some research online,我發現的一件事是,您需要爲您的裝配AllowPartiallyTrustedCallers

[assembly: AllowPartiallyTrustedCallers] 

您的項目是否啓用了?

更多鏈接:

+0

這讓我通過了原來的錯誤,但現在它提出了一個新的(看我原來的帖子,我更新了它) – spyter

+0

注意:我也嘗試通過[程序集:SecurityRules(SecurityRuleSet.Level1)]將sec級別更改爲一個,沒有運氣..:/ – spyter

+0

嗯,似乎有很多與網絡相關的問題類似的問題: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(最後一條說明中等信任問題尚未在其MVC 3版本中得到解決) –