Merge pull request #2369 from sbwalker/dev

check for existence of appsettings.json on Maui
This commit is contained in:
Shaun Walker 2022-08-16 09:42:14 -04:00 committed by GitHub
commit 6e0de6f7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,13 +63,16 @@ public static class MauiProgram
private static void LoadAppSettings()
{
string file = Path.Combine(FileSystem.Current.AppDataDirectory, "appsettings.json");
using FileStream stream = File.OpenRead(file);
using StreamReader reader = new StreamReader(stream);
var content = reader.ReadToEnd();
var obj = JsonSerializer.Deserialize<JsonObject>(content)!;
if (!string.IsNullOrEmpty((string)obj["Url"]))
if (File.Exists(file))
{
url = (string)obj["Url"];
using FileStream stream = File.OpenRead(file);
using StreamReader reader = new StreamReader(stream);
var content = reader.ReadToEnd();
var obj = JsonSerializer.Deserialize<JsonObject>(content)!;
if (!string.IsNullOrEmpty((string)obj["Url"]))
{
url = (string)obj["Url"];
}
}
}