title: Ninject.MVC3 + MediumTrust = Security Exception
body: <ol>
  <li>I created a new project of type Asp.net MVC 4</li>
  <li>I installed the package via Ninject.MVC3 NuGet <code>Install Package Ninject.MVC3</code></li>
  <li>When running the project, security error:</li>
  </ol>
  
  <h1>Error</h1>
  
  <blockquote>
    <p>Server Error in '/MediumTrustSample' Application.</p>
    
    <p>Security Exception</p>
    
    <p>Description: The application attempted to perform an operation not
    allowed by the security policy.  To grant this application the
    required permission please contact your system administrator or change
    the application's trust level in the configuration file. </p>
    
    <p>Exception Details: System.Security.SecurityException: Request for the
    permission of type 'System.Security.Permissions.ReflectionPermission,
    mscorlib, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089' failed.</p>
    
    <p>Source Error: </p>
    
    <p>Line 20:<br>
    DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule)); Line
    21:<br>
    DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
    Line 22:             bootstrapper.Initialize(CreateKernel); Line 23:<br>
    } Line 24:         </p>
    
    <p>Source File: C:\Users\Riderman_2\Documents\Visual Studio
    2010\Projects\MediumTrustSample\MediumTrustSample\App_Start\NinjectMVC3.cs
    Line: 22 </p>
    
    <p>Stack Trace: </p>
    
    <p>[SecurityException: Request for the permission of type
    'System.Security.Permissions.ReflectionPermission, mscorlib,
    Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    failed.]<br>
    System.Security.CodeAccessSecurityEngine.SpecialDemand(PermissionType
    whatPermission, StackCrawlMark&amp; stackMark) +0<br>
    System.Security.CodeAccessPermission.Demand(PermissionType
    permissionType) +30<br>
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
    invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
    Boolean skipVisibilityChecks) +281<br>
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
    invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    +38    Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition(MethodInfo
    method, BindingFlags flags) in ExtensionsForMemberInfo.cs:145<br>
    Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined(PropertyInfo
    element, Type attributeType, Boolean inherit) in
    ExtensionsForMemberInfo.cs:173<br>
    Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo
    member) in StandardInjectionHeuristic.cs:47<br>
    Ninject.Selection.&lt;>c_<em>DisplayClass3.b</em>_2(IInjectionHeuristic h) in Selector.cs:92    System.Linq.Enumerable.Any(IEnumerable<code>1
    source, Func</code>2 predicate) +149<br>
    Ninject.Selection.Selector.b_<em>1(PropertyInfo
    p) in Selector.cs:92<br>
    System.Linq.WhereEnumerableIterator<code>1.MoveNext() +156<br>
    System.Collections.Generic.List</code>1.InsertRange(Int32 index,
    IEnumerable<code>1 collection) +552<br>
    Ninject.Selection.Selector.SelectPropertiesForInjection(Type type) in
    Selector.cs:89<br>
    Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute(IPlan
    plan) in PropertyReflectionStrategy.cs:60<br>
    Ninject.Planning.&lt;&gt;c__DisplayClass3.&lt;GetPlan&gt;b__1(IPlanningStrategy s)
    in Planner.cs:68<br>
    Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable</code>1
    series, Action<code>1 action) in ExtensionsForIEnumerableOfT.cs:23<br>
    Ninject.Planning.Planner.GetPlan(Type type) in Planner.cs:70<br>
    Ninject.Activation.Context.Resolve() in Context.cs:180<br>
    Ninject.KernelBase.&lt;Resolve&gt;b__7(IContext context) in
    KernelBase.cs:375<br>
    System.Linq.WhereSelectEnumerableIterator</code>2.MoveNext() +238<br>
    System.Linq.Enumerable.SingleOrDefault(IEnumerable<code>1 source) +299<br>
    Ninject.Planning.Targets.Target</code>1.GetValue(Type service, IContext
    parent) in Target.cs:179<br>
    Ninject.Planning.Targets.Target<code>1.ResolveWithin(IContext parent) in
    Target.cs:147<br>
    Ninject.Activation.Providers.StandardProvider.GetValue(IContext
    context, ITarget target) in StandardProvider.cs:97<br>
    System.Linq.WhereSelectArrayIterator</code>2.MoveNext() +110<br>
    System.Linq.Buffer<code>1..ctor(IEnumerable</code>1 source) +488<br>
    System.Linq.Enumerable.ToArray(IEnumerable<code>1 source) +104<br>
    Ninject.Activation.Providers.StandardProvider.Create(IContext context)
    in StandardProvider.cs:81    Ninject.Activation.Context.Resolve() in
    Context.cs:157    Ninject.KernelBase.&lt;Resolve&gt;b__7(IContext context)
    in KernelBase.cs:375<br>
    System.Linq.WhereSelectEnumerableIterator</code>2.MoveNext() +238<br>
    System.Linq.d</em>_b1<code>1.MoveNext() +296<br>
    System.Linq.Enumerable.Single(IEnumerable</code>1 source) +282<br>
    Ninject.ResolutionExtensions.Get(IResolutionRoot root, IParameter[]
    parameters) in ResolutionExtensions.cs:37<br>
    Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback)
    in Bootstrapper.cs:72<br>
    MediumTrustSample.App_Start.NinjectMVC3.Start() in
    C:\Users\Riderman_2\Documents\Visual Studio
    2010\Projects\MediumTrustSample\MediumTrustSample\App_Start\NinjectMVC3.cs:22</p>
    
    <p>Version Information: Microsoft .NET Framework Version:4.0.30319;
    ASP.NET Version:4.0.30319.272</p>
  </blockquote>
  
  <h1>Question</h1>
  
  <p><strong>How to use Ninject.MVC3 with MediumTrust?</strong></p>