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

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

我正在 VS2010 中为 Windows Phone 编写 Silverlight pivot 应用程序。我刚刚添加了来自 msdn here 的示例代码.现在每次我重新加载设计器时都会出现异常:

Unable to determine application identity of the caller.

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

这是 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(调用方)正在尝试运行代码,但没有关联的应用程序(应用程序标识),因此它失败了。也许吧?

有什么想法吗?

最佳答案

您需要为 DesignerProperties.IsInDesignTool 添加支票到该代码,因为在 Visual Studio 或 Expression Blend 中访问 IsolatedStorageSettings 是无效的。

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

关于c# - 无法确定调用者的应用程序身份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7294461/

相关文章:

silverlight - 在另一个 Datagrid 的 RowDetailsTemplate 中使用 Datagrid

.net - 在 Silverlight 中使用绑定(bind)时连接字符串的方法

c# - 了解一行中使用的 Task.Run + Wait() + async + await 的使用

c# - 在 C# 中暂停/恢复上传

c# - 隐藏和显示标签和按钮

apache-flex - flex vs silverlight 学生版

c++ - VS 2010 C++ IntelliSense "a storage class may not be specified here"即使它可以?

c# - 始终在 Windows 应用程序的数据 GridView 中显示滚动条 - C#

c++ - Visual Studio 2010 c++ 编译器问题

c# - 多级锁?