Version Dependent Isolated Storage

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I'm trying to have the isolated storage created separately for each version
of a strong named assembly. The reason for this is that the data formats of
the persisted information may change from one version to another, and, if the
stores are the same for all the versions, then errors may occur when older
versions try to load information written by newer ones or vice-versa.

I guess I could append the version to each file name, or create folders with
the versions inside the isolated storage, but I'm trying to take advantage of
the isolation feature.

So far, I've managed to do this by creating an Url object from a uri-like
string containing the assembly version, and passing this to
IsolatedStorageFile.GetStore as assembly evidence.

This sounds a bit as a hack, can anyone tell me if there is an official way
to do this?

Thanks.
 
Hi

Based on my research, we can GetStore's overload version, and specified to
use StrongName as the evidence. Because if the assembly's version changed
its strongname will also change, we can use that to identify a different
store.
public void Store()
{
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly,typeof(System.Security.Policy.Url),typeof(Syst
em.Security.Policy.StrongName));
StreamWriter writer = null;
writer = new StreamWriter(new IsolatedStorageFileStream("TestStore.txt",
FileMode.CreateNew,isoStore));
writer.WriteLine(Assembly.GetExecutingAssembly().FullName);
writer.Close();
Debug.WriteLine("Write OK");
}
public void Retrieve()
{
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly,
typeof(System.Security.Policy.Url),typeof(System.Security.Policy.StrongName)
);
StreamReader reader = new StreamReader(new
IsolatedStorageFileStream("TestStore.txt", FileMode.Open,isoStore));
String sb = reader.ReadLine();
reader.Close();
Debug.WriteLine("Read "+sb);
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi

Did my suggestion help you?
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you Peter for your answer - unfortunately your suggestion does not
work; I have created a test project that adds a folder (named after the
current version & time) to the isolated storage every time it is started,
then shows the available folders in a message box. After changing the
version, the program still shows all the previously created folders - so it
does not work.

Here is some code:

AssemblyInfo.vb:
....
<Assembly: AssemblyVersion("1.5")>
<Assembly: AssemblyKeyName("Test")>
....

Form1.vb:
....
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Dim store As IsolatedStorageFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly Or
IsolatedStorageScope.Domain Or IsolatedStorageScope.User, GetType(Url),
GetType(StrongName))

store.CreateDirectory("V " & Application.ProductVersion & " " &
DateTime.Now.ToString("mm-ss"))

Dim names As String = String.Join(", ", store.GetDirectoryNames("*"))
store.Close()

MsgBox(names)

End Sub
 
Hi

The version consists of four parts in sequence as below
// Major Version
// Minor Version
// Build Number
// Revision

But the version seperated in IsolatedStorageFile is dependent on Major
Version.
i.e. if the version is 1.5.0.0, 1.0.0.0,1.5.5.0 ... then are in the same
store.
But the 2.0.0.0 will be in the another store.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks for your answer. I think I'll go for sub-folders for each version
since isolation by major version is not enough (we have intermediate releases
for testing and this means only build/minor version changes and still they
should not mix one's store with the other's)
 
Hi

That is a workaround, if you still have any concern, please feel free to
post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

I've been trying (since last week) to mark this as an answered question - I
clicked "Yes" for "Did this post answer the question?", but I'm not sure it
worked.

I appreciate your help and I wouldn't like to make you miss some points, if
this is the case. So if you need this, just let me know what to do.

Thanks.
 
Hi

Ok, I will do that. :)
And thanks for your efforts and time.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top