diff --git a/src/Microsoft.Graph.Cli.Core/Configuration/ConfigurationRoot.cs b/src/Microsoft.Graph.Cli.Core/Configuration/ConfigurationRoot.cs index 825016c1..bed6c3ff 100644 --- a/src/Microsoft.Graph.Cli.Core/Configuration/ConfigurationRoot.cs +++ b/src/Microsoft.Graph.Cli.Core/Configuration/ConfigurationRoot.cs @@ -1,3 +1,5 @@ +using System.Text.Json.Serialization; + namespace Microsoft.Graph.Cli.Core.Configuration; /// @@ -10,3 +12,8 @@ public class ConfigurationRoot /// public AuthenticationOptions AuthenticationOptions { get; set; } = new AuthenticationOptions(); } + +[JsonSerializable(typeof(ConfigurationRoot))] +internal partial class SourceGenerationContext : JsonSerializerContext +{ +} diff --git a/src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs b/src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs index e627942e..1c24eefd 100644 --- a/src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs +++ b/src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheManager.cs @@ -174,7 +174,7 @@ private void DeleteAuthenticationRecord() try { - return await JsonSerializer.DeserializeAsync(fileStream, cancellationToken: cancellationToken); + return await JsonSerializer.DeserializeAsync(fileStream, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false); } catch (Exception) { @@ -188,7 +188,7 @@ private async Task WriteConfigurationAsync(string path, ConfigurationRoot config try { using FileStream fileStream = File.Open(path, FileMode.Create, FileAccess.Write); - await JsonSerializer.SerializeAsync(fileStream, configuration, cancellationToken: cancellationToken); + await JsonSerializer.SerializeAsync(fileStream, configuration, SourceGenerationContext.Default.ConfigurationRoot, cancellationToken: cancellationToken).ConfigureAwait(false); } catch (DirectoryNotFoundException) { diff --git a/src/Microsoft.Graph.Cli.Core/Microsoft.Graph.Cli.Core.csproj b/src/Microsoft.Graph.Cli.Core/Microsoft.Graph.Cli.Core.csproj index 0e26681f..0a0f8c9b 100644 --- a/src/Microsoft.Graph.Cli.Core/Microsoft.Graph.Cli.Core.csproj +++ b/src/Microsoft.Graph.Cli.Core/Microsoft.Graph.Cli.Core.csproj @@ -9,6 +9,7 @@ embedded 1.0.0 preview.8 + true diff --git a/src/sample/sample.csproj b/src/sample/sample.csproj index f06b1e1f..a8c3c7d9 100644 --- a/src/sample/sample.csproj +++ b/src/sample/sample.csproj @@ -5,6 +5,7 @@ net7.0 disable enable + $(NoWarn);CS8669 @@ -20,4 +21,4 @@ - \ No newline at end of file +