System.InvalidCastException:'无法将类型为'ApplicationView'的对象强制转换为'IApplicationView9 [英] System.InvalidCastException: 'Unable to cast object of type 'ApplicationView' to type 'IApplicationView9
问题描述
var displayRegion = ApplicationView.GetForCurrentView()。GetDisplayRegions()
在某些设备中,我收到此异常System.InvalidCastException:'无法强制转换类型为 Windows.UI.ViewManagement.ApplicationView的对象以键入 Windows.UI.ViewManagement.IApplicationView9。如何避免这种异常?
var displayRegion= ApplicationView.GetForCurrentView().GetDisplayRegions()
In some devices, I am getting this exception, System.InvalidCastException: 'Unable to cast object of type 'Windows.UI.ViewManagement.ApplicationView' to type 'Windows.UI.ViewManagement.IApplicationView9'. How to avoid this exception?
推荐答案
GetDisplayRegions
API的引入Windows 10版本1903(在10.0.18362.0中引入)(请参阅文档)。这意味着您必须首先检查当前设备上是否存在API 使用 APIInformation.IsMethodPresent
。
The GetDisplayRegions
API was introduced in Windows 10, version 1903 (introduced in 10.0.18362.0) (see Docs). This means you have to first check if the API is present on the current device using APIInformation.IsMethodPresent
.
这篇关于System.InvalidCastException:'无法将类型为'ApplicationView'的对象强制转换为'IApplicationView9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!