本文介绍了UnauthorizedAccessException在初始化ProximityDevice(Windows手机)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 ProximityDevice
在我的应用程序。我若为外地或在构造函数中,像这样的:
I want to use ProximityDevice
in my application. If I declare it as field or in the constructor, like this:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public ProximityDevice device;
public MainPage() {
InitializeComponent();
device = ProximityDevice.GetDefault();
}
}
或这样的:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public MainPage() {
InitializeComponent();
public ProximityDevice device = ProximityDevice.GetDefault();
}
}
我收到
A first chance exception of type 'System.UnauthorizedAccessException' occurred in SecurityClient.DLL
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll
如果我把它声明为静态code使没有问题:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public static ProximityDevice device = ProximityDevice.GetDefault();
public MainPage() {
InitializeComponent();
}
}
如何解决这个问题?
How to fix that problem?
推荐答案
请确保您添加的ID_CAP_PROXIMITY能力,你的应用程序清单。
Make sure you added the ID_CAP_PROXIMITY capability to your application manifest.
这篇关于UnauthorizedAccessException在初始化ProximityDevice(Windows手机)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!