WASM: directory created using CreateDirectory does not exist after restart #4987
-
Current behaviorWASM: Directory.CreateDirectory creates the directory but only for the current session. When you restart, the directory does not exist. Using CreateFolderAsync works but that is then incompatible with my existing WPF code. Expected behaviorShould create directory and when I load the application again the directory should exist. Not entirely clear how to verify the creation of the directory through the Google debugging tools though. How to reproduce it (as minimally and precisely as possible)run the enclosed project in wasm mode: Click open message box. restart the application. Click open message box. Workaroundbeen unable to find anything in the documentation around system.IO or createdirectory. It will be very difficult to rewrite my WPF code and creates a mess of file system code if I have have different file system code between WPF and Wasm. this code appears to work on android. EnvironmentNuget Package:
Nuget Package Version(s): Affected platform(s):
IDE:
Relevant plugins:
Anything else we need to know? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Thanks for the report. This is not a bug, but a restriction of the behavior of browsers, where the availability of persisted folders can only be ensured after the return of any async method of You should perform the initialization of your application in an async method invoked from You can view additional information here. |
Beta Was this translation helpful? Give feedback.
-
That doesn't actually address the issue. in the sample code I call a async method of Windows storage and then the system file apis still don't work. documentation does talk about using system I/O file APIs. Is no indication that I'vve done anything wrong with what I'm doing - I'm calling an aysnc method and then calling system.io Apis |
Beta Was this translation helpful? Give feedback.
-
Thanks for the update. |
Beta Was this translation helpful? Give feedback.
-
@stefanolson I have tested the code and found the reason why the folder disappears. In WASM, folders that are persistent across launches need to be specifically marked. This is the case for folders under To allow your System.IO folder to persist as well, you need to create it under the same path:
|
Beta Was this translation helpful? Give feedback.
-
Great. That now works in my sample app. Hopefully that can be somehow integrated into documentation. I did search on system.io and couldn't find anything. Thanks. |
Beta Was this translation helpful? Give feedback.
-
@stefanolson that particular bit of information is mentioned in this document. |
Beta Was this translation helpful? Give feedback.
@stefanolson I have tested the code and found the reason why the folder disappears. In WASM, folders that are persistent across launches need to be specifically marked. This is the case for folders under
ApplicationData
- for exampleLocalFolder
andRoamingFolder
(see here for the code). This is the reason the folder created using theStorageFolder
API persists - because it is under theApplicationData.LocalFolder.Current
path.To allow your System.IO folder to persist as well, you need to create it under the same path: