![](/img/trans.png)
[英]how to use this IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication(); in WP 8.1
[英]How to use IsolatedStorageFile.GetUserStoreForApplication()
我有一個 clickonce 應用程序,它在生產中運行良好,方法如下:
IsolatedStorageFile.GetUserStoreForApplication()
成功執行。 當我嘗試調試我的應用程序時,它會因“無法確定調用者的應用程序身份......” 而崩潰並出現IsolatedStorageException, 如此處所述
使用此方法時,與應用程序關聯的所有程序集都使用相同的獨立存儲。 僅當可以確定應用程序標識時才可以使用此方法 - 例如,當應用程序通過 ClickOnce 部署發布或者是基於 Silverlight 的應用程序時。 如果您嘗試在基於 ClickOnce 或 Silverlight 的應用程序之外使用此方法,您將收到一個 IndependentStorageException 異常,因為無法確定調用者的應用程序標識。
我的問題是如何使用 IndependentStorageFile.GetUserStoreForApplication() 和調試應用程序無一例外?
首先檢查激活上下文是否為空,
public IsolatedStorageFile getIsolatedStorage() {
return AppDomain.CurrentDomain.ActivationContext == null
? IsolatedStorageFile.GetUserStoreForAssembly()
: IsolatedStorageFile.GetUserStoreForApplication();
}
這將表明該域沒有激活上下文,這意味着無法確定調用者的應用程序身份。
我還看到了另一個實現
參考ClickOnce 和 IndependentStorage
他們檢查System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
以確定應用程序當前是否在部署后單擊
public IsolatedStorageFile getIsolatedStorage() {
return System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
? IsolatedStorageFile.GetUserStoreForApplication()
: IsolatedStorageFile.GetUserStoreForAssembly();
}
理想情況下,我還建議將IsolatedStorage
封裝在一個抽象之后,以便單元測試也可以獨立完成而不會產生影響。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.