我從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.
什麼是內部異常?你是從一個標準的MVC網站運行嗎?你使用的是什麼版本的.NET? –
.NET v4,MVC4和內部ex是空的 – spyter
你有沒有得到這個地方?我正在將Ninject 2.2的MVC4項目升級到3.0,並獲得類似的問題。 – mackie