【问题标题】:UnauthorizedAccessException while initializing ProximityDevice (Windows Phone)初始化 ProximityDevice 时出现 UnauthorizedAccessException (Windows Phone)
【发布时间】:2014-01-20 16:44:52
【问题描述】:

我想在我的应用程序中使用ProximityDevice。如果我将其声明为字段或在构造函数中,如下所示:

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

如果我将其声明为静态代码不会导致任何问题:

 public partial class MainPage : PhoneApplicationPage {
        // Constructor
        public static  ProximityDevice device = ProximityDevice.GetDefault();
        public MainPage() {
            InitializeComponent();       
        }
    }

如何解决这个问题?

【问题讨论】:

    标签: c# .net windows-phone unauthorizedaccessexcepti


    【解决方案1】:

    确保您已将 ID_CAP_PROXIMITY 功能添加到您的应用程序清单中。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    相关资源
    最近更新 更多