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

13

我正在为 Windows Phone 写一个 Silverlight 透视应用程序,使用 VS2010。我刚刚从 msdn 这里 添加了示例代码。现在每当我重新加载设计器时,都会出现异常:

无法确定调用者的应用程序标识。

at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type appEvidenceType)

at System.IO.IsolatedStorage.IsolatedStorageFile.GetStore(IsolatedStorageScope scope, Type applicationEvidenceType)

at System.IO.IsolatedStorage.IsolatedStorageSettings.get_ApplicationSettings() at SettingsSample.AppSettings..ctor() in C:..\Settings.cs:line 34

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

Visual Studio/Windows Phone SDK 是否存在漏洞?

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个回答

30

由于在 Visual Studio 或 Expression Blend 中访问 IsolatedStorageSettings 是无效的,因此您需要向该代码添加一个检查,以检查DesignerProperties.IsInDesignTool

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接