<p>I save stuff in an <a href="http://msdn.microsoft.com/en-us/library/3ak841sy.aspx" rel="nofollow noreferrer">Isolated Storage</a> file (using class IsolatedStorageFile). It works well, and I can retrieve the saved values when calling the saving and retrieving methods in my <a href="http://en.wikipedia.org/wiki/Data_access_layer" rel="nofollow noreferrer">DAL</a> layer from my GUI layer. However, when I try to retrieve the same settings from another assembly in the same project, it gives me a FileNotFoundException. What do I do wrong? This is the general concept:</p>

<pre><code>    public void Save(int number)
    {
        IsolatedStorageFile storage = IsolatedStorageFile.GetMachineStoreForAssembly();
        IsolatedStorageFileStream fileStream =
            new IsolatedStorageFileStream(filename, FileMode.OpenOrCreate, storage);

        StreamWriter writer = new StreamWriter(fileStream);
        writer.WriteLine(number);
        writer.Close();
    }

    public int Retrieve()
    {
        IsolatedStorageFile storage = IsolatedStorageFile.GetMachineStoreForAssembly();
        IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(filename, FileMode.Open, storage);

        StreamReader reader = new StreamReader(fileStream);

        int number;

        try
        {
            string line = reader.ReadLine();
            number = int.Parse(line);
        }
        finally
        {
            reader.Close();
        }

        return number;
    }
</code></pre>

<p>I've tried using all the GetMachineStoreFor* scopes.</p>

<p>EDIT: Since I need several assemblies to access the files, it doesn't seem possible to do with isolated storage, unless it's a <a href="http://en.wikipedia.org/wiki/ClickOnce" rel="nofollow noreferrer">ClickOnce</a> application.</p>

[{'answer_id': 72736, 'author': 'icelava', 'author_id': 2663, 'author_profile': 'https://Stackoverflow.com/users/2663', 'pm_score': 3, 'selected': True, 'text': '<p>When you instantiated the IsolatedStorageFile, did you scope it to IsolatedStorageScope.Machine?</p>\n\n<p>Ok now that you have illustrated your code style and I have gone back to retesting the behaviour of the methods, here is the explanation:</p>\n\n<ul>\n<li>GetMachineStoreForAssembly() - scoped to the machine and the assembly identity. Different assemblies in the same application would have their own isolated storage.</li>\n<li>GetMachineStoreForDomain() - a misnomer in my opinion. scoped to the machine and the domain identity <em>on top of</em> the assembly identity. There should have been an option for just AppDomain alone.</li>\n<li>GetMachineStoreForApplication() - this is the one you are looking for. I have tested it and different assemblies can pick up the values written in another assembly. The only catch is, the <em>application identity</em> must be verifiable. When running locally, it cannot be properly determined and it will end up with exception "Unable to determine application identity of the caller". It can be verified by deploying the application via Click Once. Only then can this method apply and achieve its desired effect of shared isolated storage.</li>\n</ul>\n'}, {'answer_id': 73400, 'author': 'Abe Heidebrecht', 'author_id': 9268, 'author_profile': 'https://Stackoverflow.com/users/9268', 'pm_score': 1, 'selected': False, 'text': '<p>When you are saving, you are calling GetMachineStoreForDomain, but when you are retrieving, you are calling GetMachineStoreForAssembly.</p>\n\n<p>GetMachineStoreForAssembly is scoped to the assembly that the code is executing in, while the GetMachineStoreForDomain is scoped to the currently running AppDomain and the assembly where the code is executing.  Just change your these calls to GetMachineStoreForApplication, and it should work.</p>\n\n<p>The documentation for IsolatedStorageFile can be found at <a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile_members.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile_members.aspx</a></p>\n'}]
['https://Stackoverflow.com/questions/72626', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3397/']