Closed j4587698 closed 1 year ago
Yeah, previewer starts your program in preview mode, so if your components have side effects, then those will be applied.
The only way around that is to either restructure the program to not open files in design mode, or to open files with shared access.
Nothing could be done in the plugin, unfortunately.
Ok, I can use Design.IsDesignMode
. It works normally. But AvaloniaVs can work normally with out Design.IsDesignMode
Could you please share some steps to reproduce the issue, then? If it works in AvaloniaVS but doesn't in AvaloniaRider, that's quite unexpected.
Yes, I create a repo : https://github.com/j4587698/IDETest It's only open a db file for litedb. Open MainWindow.axaml at tab. If in rider, it will throw IOException, but it's running in vs.
@j4587698, I'm sorry, the project is either deleted or private. I have no access to it. Could you please help?
Sorry, The repo created by vs is private by default. I didn't notice. Now it is public.
Ok, here's how it works.
AvaloniaVS starts previewer with CWD = solution directory, and so your code reads MyDb.db
from the solution directory while in preview mode.
When you start your program in run/debug mode, it runs with CWD = bin directory by default (i.e. bin\Debug\net6.0
).
This way, the previewer and the program itself use different files, and there's no clash.
AvasloniaRider starts previewer with exact same CWD as the program itself: both the previewer and the program use same CWD, bin\Debug\net6.0
. So, they both open the same file, and this prevents your program from working correctly.
I'm thinking of adding a setting for that. I still believe that using the same CWD as run mode is a good idea. But for cases like yours, when the users may want to change that default and use some other directory (say, a solution one or some other).
If files are used in the viewmodel constructor, when debugging will throw System.IO.IOException. It looks like this file is occupied by the previewer. If close the axaml page tab, the program can run normally. Selecting edit only cannot solve this problem.