在winform或者控制台程序中使用下面代码时,会抛出IsolatedStoreExceptio:Unable to determine application identity of the caller

using (var isolatedFile = IsolatedStorageFile.GetMachineStoreForApplication())
{

}

using (var isolatedFile = IsolatedStorageFile.GetUserStoreForApplication())
{

}

出现这个异常的原因是机器范围和应用范围内的独立存储只能在ClickOnce程序部署后使用。如果你的程序不是通过ClickOnce部署后执行的你就会看到“Unable to determine the application identity of the caller”.

使用下面代码可以正常执行:

using (var isolatedFile = IsolatedStorageFile.GetUserStoreForAssembly())
{

}

相关文章: