Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Function with .NET and AOT produces Exception: System.InvalidOperationException: Reflection-based serialization #2715

Open
shotyme opened this issue Sep 6, 2024 · 5 comments
Assignees
Labels
bug Something isn't working Needs: Attention 👋

Comments

@shotyme
Copy link

shotyme commented Sep 6, 2024

Hi,

when I create a new Azure Function v4 with .NET8 in isolated-worker mode and add

<PropertyGroup>
 <PublishAot>true</PublishAot>
</PropertyGroup>

to the .csproj I get this exception on the startup:

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.
[2024-09-06T13:56:38.895Z]    at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
[2024-09-06T13:56:38.895Z]    at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
[2024-09-06T13:56:38.896Z]    at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
[2024-09-06T13:56:38.897Z]    at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
[2024-09-06T13:56:38.897Z]    at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
[2024-09-06T13:56:38.897Z]    at Microsoft.Azure.Functions.Worker.Grpc.FunctionMetadata.FunctionMetadataRpcExtensions.GetBindingInfoList(IFunctionMetadata funcMetadata) in D:\a\_work\1\s\src\DotNetWorker.Grpc\FunctionMetadata\FunctionMetadataRpcExtensions.cs:line 29
[2024-09-06T13:56:38.898Z]    at Microsoft.Azure.Functions.Worker.GrpcWorker.GetFunctionMetadataAsync(String functionAppDirectory) in D:\a\_work\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 185
Stack:    at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
[2024-09-06T13:56:38.898Z]    at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
[2024-09-06T13:56:38.899Z]    at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
[2024-09-06T13:56:38.899Z]    at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options)
[2024-09-06T13:56:38.900Z]    at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
[2024-09-06T13:56:38.900Z]    at Microsoft.Azure.Functions.Worker.Grpc.FunctionMetadata.FunctionMetadataRpcExtensions.GetBindingInfoList(IFunctionMetadata funcMetadata) in D:\a\_work\1\s\src\DotNetWorker.Grpc\FunctionMetadata\FunctionMetadataRpcExtensions.cs:line 29
[2024-09-06T13:56:38.901Z]    at Microsoft.Azure.Functions.Worker.GrpcWorker.GetFunctionMetadataAsync(String functionAppDirectory) in D:\a\_work\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 185.
[2024-09-06T13:56:38.935Z] 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.

The Azure Function was created by the Visual Studio 2022 template and just contained the boilderplate HttpTrigger. If you remove the PublishAot option from your csproj you should remove the bin and obj folder and it should start again. Same goes the other way around when you add it back in and you want to produce the issue again.
Do I miss something here?

@shotyme shotyme added the bug Something isn't working label Sep 6, 2024
@KondzioSSJ4
Copy link

As far as I remember AoT is not supported by Azure Functions
To be honest... I would try to do some work to make AoT possible

Is there any threat or list of required job to make?

Most part what I think that would be required would be related to removing json files with configurations of the functions
and instead of that just making source generated precompiled parts
but... to make it easier I guessing the better would be starting with providing VerifyTests/Verify.SourceGenerators into project to make it easy to validate what generators generate

@bhagyshricompany bhagyshricompany self-assigned this Sep 10, 2024
@bhagyshricompany
Copy link

bhagyshricompany commented Sep 10, 2024

Hi @shotyme thanks for reporting but why you using AOT.
please share the all repro steps.

@shotyme
Copy link
Author

shotyme commented Sep 10, 2024

@bhagyshricompany I want to use AOT in my functions to have super fast Start-Up time. I read something like theoretical 2-3 times faster with AOT. This would be huge.

@kshyju kshyju transferred this issue from Azure/Azure-Functions Sep 17, 2024
@shotyme
Copy link
Author

shotyme commented Sep 23, 2024

As I wrote in my initial post: Steps for reproduction:

  1. Create a Azure Function with HttpTrigger via Visual Studio 2022
  2. Change the .csproj and add
<PropertyGroup>
 <PublishAot>true</PublishAot>
</PropertyGroup>

You will get a System.InvalidOperationException: Reflection-based serialization

@bhagyshricompany
Copy link

bhagyshricompany commented Sep 24, 2024

Hi @KondzioSSJ4 Thanks for patience .Will discuss and update. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Attention 👋
Projects
None yet
Development

No branches or pull requests

3 participants