- 我创建了一个 Asp.net MVC 4 类型的新项目
- 我通过 Ninject.MVC3 NuGet 安装了这个包
Install Package Ninject.MVC3
- 运行项目时,安全错误:
错误
“/MediumTrustSample”应用程序中的服务器错误。
安全异常
说明:应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或在配置文件中更改应用程序的信任级别。
异常详细信息:System.Security.SecurityException:请求“System.Security.Permissions.ReflectionPermission,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”类型的权限失败。
源错误:
第 20 行:
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule)); 第 21 行:
DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule)); 第 22 行:bootstrapper.Initialize(CreateKernel); 第 23 行:
} 第 24 行:源文件:C:\Users\Riderman_2\Documents\Visual Studio 2010\Projects\MediumTrustSample\MediumTrustSample\App_Start\NinjectMVC3.cs 行:22
堆栈跟踪:
[SecurityException:请求'System.Security.Permissions.ReflectionPermission,mscorlib,Version = 4.0.0.0,Culture = Neutral,PublicKeyToken = b77a5c561934e089'类型的权限失败。]
System.Security.CodeAccessSecurityEngine.SpecialDemand(PermissionType whatPermission,StackCrawlMark& stackMark ) +0
System.Security.CodeAccessPermission.Demand(PermissionType permissionType) +30
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] 参数, CultureInfo 文化, Boolean skipVisibilityChecks) +281
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfoculture) +38 Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition(MethodInfo method, BindingFlags flags) in ExtensionsForMemberInfo.cs:145
Ninject ExtensionsForMemberInfo.cs:173
Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo member) in StandardInjectionHeuristic.cs:47
Ninject.Selection.IsDefined (PropertyInfo element, Type attributeType, Boolean inherit) Selector.cs 中的DisplayClass3.b _2(IInjectionHeuristic h):92 System.Linq.Enumerable.Any(IEnumerable1 source, Func
2 谓词)+149
Selector.cs:92
System.Linq.WhereEnumerableIterator1.MoveNext() +156
System.Collections.Generic.List1 collection) +552
Ninject.Selection.Selector.SelectPropertiesForInjection(Type type) in Selector.cs:89
Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute(IPlan plan) in PropertyReflectionStrategy.cs:60
Ninject.Planning.<>c__DisplayClass3.<GetPlan>b__1(IPlanningStrategy s) in Planner.cs:68
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1 action) in ExtensionsForIEnumerableOfT.cs:23
Ninject.Planning.Planner.GetPlan(Type type) in Planner.cs:70
Ninject.Activation.Context.Resolve() in Context.cs:180
Ninject.KernelBase.<Resolve>b__7(IContext context) in KernelBase.cs:375
System.Linq.WhereSelectEnumerableIterator1 source) +299
Ninject.Planning.Targets.Target1.ResolveWithin(IContext parent) in Target.cs:147
Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in StandardProvider.cs:97
System.Linq.WhereSelectArrayIterator1..ctor(IEnumerable
1 source) +104
Ninject.Activation.Providers.StandardProvider.Create(IContext context) in StandardProvider.cs:81 Ninject.Activation.Context.Resolve() in Context.cs:157 Ninject.KernelBase.<Resolve>b__7(IContext context) in KernelBase.cs:375
System.Linq.WhereSelectEnumerableIterator
1.InsertRange (Int32 index, IEnumerable 1 series, Action 2.MoveNext() +238 System.Linq.Enumerable.SingleOrDefault( IEnumerable 1.GetValue(Type service, IContext parent) in Target.cs:179 Ninject.Planning.Targets.Target 2.MoveNext() +110 System.Linq.Buffer 1 source) +488 System.Linq.Enumerable.ToArray(IEnumerable 2.MoveNext() +238 System.Linq.d _b1 1 source) +282 Ninject.ResolutionExtensions.Get(IResolutionRoot root, IParameter[] parameters) in ResolutionExtensions.cs:371.MoveNext() +296
System.Linq.Enumerable.Single(IEnumerable
Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback) 在 Bootstrapper.cs:72
MediumTrustSample.App_Start.NinjectMVC3.Start() 在 C:\Users\Riderman_2\Documents\Visual Studio 2010\Projects\MediumTrustSample\MediumTrustSample\ App_Start\NinjectMVC3.cs:22版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.272
问题
如何将 Ninject.MVC3 与 MediumTrust 一起使用?