I know that this is not quite the same, but I solved it by saving the data in the application folder like this:
var userDataPath = Path.Combine(AppContext.BaseDirectory, "userdata.json");
Of course, you can also take a subfolder of AppContext.BaseDirectory .
source share