Monday, December 3, 2012

First chance FileNotFoundException when calling IsolatedStorageFile.OpenFile

First chance FileNotFoundException when calling IsolatedStorageFile.OpenFile

Somewhere in my code, I have this line:

return _store.OpenFile(path, fileMode); 

With fileMode being sometimes FileMode.Create and sometimes FileMode.Open. Everything works well, I always get a valid stream and if necessary, the file is correctly created.

But, I've just discovered in my VS output that I have the following message every time I call the method where the above line is:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

I get this error when the file is created and I also get this error when the file is overwritten (and obviously exists).

I'm just curious about these errors since everything works perfectly.

Thanks,

EDIT: Same thing with new IsolatedStorageFileStream(...). Everything works fine but I still get the "first chance exception" message.

Answers & Comments...

Answer: 1
var isf = IsolatedStorageFile.GetUserStoreForApplication(); IsolatedStorageFileStream isfs;  if (!isf.FileExists(_filename))     isfs = new IsolatedStorageFileStream(_filename, System.IO.FileMode.Create, isf); else     isfs = new IsolatedStorageFileStream(_filename, System.IO.FileMode.Open, isf);   var writer = XmlWriter.Create(isfs); xml.Save(writer);  writer.Close(); isfs.Close(); isfs.Dispose(); isf.Dispose(); 
by : Masoomianhttp://stackoverflow.com/users/909150




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog