首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >类型“”System.Net.Http.WebRequestHandler“”违反了继承安全规则“

类型“”System.Net.Http.WebRequestHandler“”违反了继承安全规则“
EN

Stack Overflow用户
提问于 2016-07-28 10:48:54
回答 5查看 10.3K关注 0票数 23

我正在尝试通过图形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 

由于我是一个初学者,我对这个错误感到震惊。有人能告诉我需要做些什么来克服这个错误吗?

EN

回答 5

Stack Overflow用户

发布于 2017-03-09 21:13:48

现在似乎这个bug已经在GitHub (https://github.com/dotnet/corefx/issues/11100)上被修复了,一个新版本的System.Net.Http已经发布了。

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

票数 38
EN

Stack Overflow用户

发布于 2016-08-12 22:09:39

这对我很有效: System.Net.Http v4.1.0.0似乎有一些问题。在web.config或app.config中,指向旧版本(v4.0.0.0)

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     ...
        <dependentAssembly>
            <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.0.0.0" />
        </dependentAssembly>

请注意,当您安装一个新的不相关的NuGet包时,绑定更改可能会被覆盖,并且您需要再次将bindingRedirect设置为4.0.0.0。

票数 25
EN

Stack Overflow用户

发布于 2017-04-14 05:53:57

我发现通过Nuget升级System.Net.Http可以解决这个问题。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38626316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档