asp.net - 类型 : 'System.Net.Http.WebRequestHandler' 违反了继承秒规则

标签 asp.net owin typeloadexception

我正在尝试通过图形 API 访问 Active Directory 数据。我在运行应用程序时收到以下错误。

描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:“System.TypeLoadException:类型违反了继承安全规则:“System.Net.Http.WebRequestHandler”。派生类型必须与基类型的安全可访问性相匹配或者不太容易访问。”

来源错误:

执行当前 Web 请求期间生成未处理的异常。有关异常来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

堆栈跟踪:

[TypeLoadException: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.]
   Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationMiddleware.ResolveHttpMessageHandler(OpenIdConnectAuthenticationOptions options) +0
   Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationMiddleware..ctor(OwinMiddleware next, IAppBuilder app, OpenIdConnectAuthenticationOptions options) +996
   lambda_method(Closure , OwinMiddleware , IAppBuilder , OpenIdConnectAuthenticationOptions ) +54

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92
   System.Delegate.DynamicInvokeImpl(Object[] args) +117
   System.Delegate.DynamicInvoke(Object[] args) +12
   Microsoft.Owin.Builder.AppBuilder.BuildInternal(Type signature) +236
   Microsoft.Owin.Builder.AppBuilder.Build(Type returnType) +21
   Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +565
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +58
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +95
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
   System.Threading.LazyInitializer.EnsureInitialized(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +72
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +96
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +523
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +364
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +770
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +195


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1069.1 

由于我是初学者,我对这个错误感到震惊。任何人都可以告诉我需要做什么来克服这个错误

最佳答案

看来该错误现已在 GitHub ( https://github.com/dotnet/corefx/issues/11100 ) 上关闭,并且新版本的 System.Net.Http 已发布。

我能够使用 NuGet 将 System.Net.Http 升级到版本 4.3.1,从而解决了该问题。

关于asp.net - 类型 : 'System.Net.Http.WebRequestHandler' 违反了继承秒规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38626316/

相关文章:

c# - GetTypes() 和 TypeLoadException 错误

html - 表格行没有突出显示onclick

c# - OWIN 干扰 log4net

c# - 将 sqldatareader 绑定(bind)到 gridview c#

asp.net - OWIN - 签署和加密请求

c# - IApplicationBuilder 映射分支在 ASP.NET 5 中未按预期工作

c# - TypeLoadException 未被 try/catch 捕获

c# - Assembly.GetTypes() - 获取加载失败的类型

javascript - 验证复选框字段 - ASP.NET 和 jQuery

c# - .Net 表单 POST