Reputation: 11
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:
An exception of type 'System.InvalidCastException' occurred in App2.exe but was not handled in user code
Additional information: Unable to cast object of type 'Windows.Web.Http.Filters.HttpBaseProtocolFilter' to type 'Windows.Web.Http.Filters.IHttpBaseProtocolFilter4'.
How can I use "HttpBaseProtocolFilter.ClearAuthenticationCache()"?
Upvotes: 1
Views: 455
Reputation: 5137
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.
It means that the Windows.Web.Http.Filters.IHttpBaseProtocolFilter4 is not available in older version and you recieve an InvalidCastException
.
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
}
Upvotes: 1