无法确定呼叫者的应用程序身份?

时间:2011-09-03 16:48:39

标签: c# silverlight visual-studio-2010 exception windows-phone-7

我正在VS2010 for Windows Phone中编写Silverlight透视应用程序。我刚刚添加了msdn here的示例代码。现在,每当我重新加载设计器时,我都会遇到异常:

  

无法确定来电者的应用身份。

     

在System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope范围,输入appEvidenceType)

     

在System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope范围,输入applicationEvidenceType)

     

at System.IO.IsolatedStorage.IsolatedStorageSettings.get_ApplicationSettings()     at C:.. \ Settings.cs中的SettingsSample.AppSettings..ctor():第34行

这是Visual Studio / Windows Phone SDK中的错误吗?

这是第34行构造函数中的代码:

public AppSettings()
    {
        // Get the settings for this application.
        try
        {
            settings = IsolatedStorageSettings.ApplicationSettings;
        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

我添加了try-catch以查看发生了什么。

我怀疑Visual Studio(调用者)正在尝试运行代码,但没有关联的应用程序(应用程序标识),因此它失败了。可能?

有什么想法吗?

1 个答案:

答案 0 :(得分:30)

由于访问Visual Studio或Expression Blend中的IsolatedStorageSettings无效,您需要向该代码添加DesignerProperties.IsInDesignTool检查。

if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
{
     settings = IsolatedStorageSettings.ApplicationSettings; 
}