Azure / AppConfiguration-DotnetProvider

The .NET Standard configuration provider for Azure App Configuration
https://github.com/Azure/AppConfiguration
MIT License
82 stars 37 forks source link

System.InvalidOperationException: Reflection-based serialization has been disabled for this application #537

Closed scorpionfly7 closed 5 months ago

scorpionfly7 commented 6 months ago

How to resolve this: Unhandled Exception: System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property. at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled() + 0x30 at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer() + 0x44 at Microsoft.Extensions.Configuration.AzureAppConfiguration.JsonKeyValueAdapter.ProcessKeyValue(ConfigurationSetting, Logger, CancellationToken) + 0xac at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d38.MoveNext() + 0x138 --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x90 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68 at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d29.MoveNext() + 0x1b4 --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x90 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68 at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d32.MoveNext() + 0x4cc --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x90 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68 at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d31.MoveNext() + 0xe0 --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x90 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68 at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.d__30.MoveNext() + 0x1b8 --- End of stack trace from previous location --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x24 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x90 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x68 at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationProvider.Load() + 0x24c at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(IConfigurationSource) + 0x44

amerjusupovic commented 6 months ago

Hi @scorpionfly7, based on the exception I was able to find this documentation about the issue. The provider uses reflection-based serialization for json values, so it seems like this issue is expected for native AOT apps. Do you know if it's enabled for your application? If not, could you tell me more about the type of application you have and the version of .NET it uses?

scorpionfly7 commented 6 months ago

@amerjusupovic We don’t want to enable this feature for whole app. We have .net core application, . Net 8, using last version of app configuration SDK. Is there way, which not requires turn on of that option?

amerjusupovic commented 6 months ago

@scorpionfly7 Currently, using key-values with application/json in the content type won't work while reflection-based serialization is disabled. We do intend to allow native AOT apps to use all of the features of App Configuration though, so we're looking into a solution. Thank you for bringing up this issue.