HttpBaseProtocolFilter.ClearAuthenticationCache()throw'System.InvalidCastException' [英] HttpBaseProtocolFilter.ClearAuthenticationCache() throw 'System.InvalidCastException'

查看:399
本文介绍了HttpBaseProtocolFilter.ClearAuthenticationCache()throw'System.InvalidCastException'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的uwp应用程序。 sdk版本为通用Windows 10.0.14332.0。应用程序什么也不做,只调用函数HttpBaseProtocolFilter.ClearAuthenticationCache()。但是当我调用HttpBaseProtocolFilter.ClearAuthenticationCache()时,抛出一个异常:

I create an simple uwp app. The sdk version is Universal Windows 10.0.14332.0. The app does nothing, only call the function "HttpBaseProtocolFilter.ClearAuthenticationCache()". But when I call the "HttpBaseProtocolFilter.ClearAuthenticationCache()", an exception throwed:


发生类型'System.InvalidCastException'的异常
App2.exe但未在用户代码中处理

An exception of type 'System.InvalidCastException' occurred in App2.exe but was not handled in user code

其他信息:无法投射Windows.Web类型的对象.http.Filters.HttpBaseProtocolFilter'来键入'Windows.Web.Http.Filters.IHttpBaseProtocolFilter4'。

Additional information: Unable to cast object of type 'Windows.Web.Http.Filters.HttpBaseProtocolFilter' to type 'Windows.Web.Http.Filters.IHttpBaseProtocolFilter4'.

如何使用HttpBaseProtocolFilter.ClearAuthenticationCache()?

How can I use "HttpBaseProtocolFilter.ClearAuthenticationCache()"?

推荐答案

根据文档中,ClearAuthenticationCache方法在Windows.Foundation.UniversalApiContract版本3中引入,并且在操作系统版本10.0中可用.14295.0和更高版本。

According to the documentation, the ClearAuthenticationCache method is introduced in Windows.Foundation.UniversalApiContract, version 3 and is available in OS version 10.0.14295.0 and later.

这意味着Windows.Web.Http.Filters.IHttpBaseProtocolFilter4在旧版本中不可用,并且您收到 InvalidCastException

It means that the Windows.Web.Http.Filters.IHttpBaseProtocolFilter4 is not available in older version and you recieve an InvalidCastException.

因此,如果您将旧版本作为最低目标,则需要:com / buildingapps / 2015/09/15 / dynamic-detection-features-with-api-contracts-10-by-10 /rel =nofollow

So if you are targetting an older version as minimum, you need to check if the API is available before calling the method:

using Windows.Foundation.Metadata;
 ...
 ...
if(ApiInformation.IsMethodPresent("Windows.Web.Http.Filters.HttpBaseProtocolFilter.ClearAuthenticationCache"))
{
    // Call the method here
}

这篇关于HttpBaseProtocolFilter.ClearAuthenticationCache()throw'System.InvalidCastException'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆