"No parameterless constructor defined for type..." when serializing record with List<T>, on AOT compiled binary
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
Direção de pesquisa
Reproduce the failure using the provided record types and the dotnet publish command with PublishAOT enabled. Start at DynamicGenericResolverGetFormatterHelper.GetFormatter and DynamicGenericResolver.FormatterCache in the stack trace, then inspect how GeneratedMessagePackResolver.ItemsRequestFormatter resolves List. Done means the sample serializes successfully in the AOT-published binary without the missing-constructor exception.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Bug description
When AOT-compiled, serializing a record with a List property throws a MessagePackSerializationException indicating there's "No parameterless constructor defined for type 'MessagePack.Formatters.ListFormatter`1[...]'".
Repro steps
using System.Text.Json.Serialization;
using MessagePack;
namespace MessagePackBug;
[MessagePackObject]
public record ItemsRequest(
[property:Key(0)]
string Prop1,
[property:Key(1)]
string Prop2,
[property:Key(2)]
List<Item> Items);
[MessagePackObject]
public record Item(
[property:Key(0)] string Prop1,
[property:Key(1)] string Prop2
);
class Program
{
static void Main()
{
var req = new ItemsRequest(
"prop1",
"prop2",
[
new Item("1", "2"),
new Item("3", "4")
]);
var result = MessagePackSerializer.Serialize(req);
Console.WriteLine(Convert.ToHexString(result));
}
}
compile with AOT option and run. I used following script:
dotnet publish --self-contained=true -o "bin/publish-product"
.\bin\publish-product\MessagePackBug.exe
Expected behavior
serialize without any error
Actual behavior
Restore complete (0.2s)
MessagePackBug succeeded with 2 warning(s) (7.5s) → bin\publish-product\
C:\Users\ksi12\.nuget\packages\messagepack\3.1.2\lib\net9.0\MessagePack.dll : warning IL3053: Assembly 'MessagePack' produced AOT analysis warnings.
C:\Users\ksi12\.nuget\packages\messagepack\3.1.2\lib\net9.0\MessagePack.dll : warning IL2104: Assembly 'MessagePack' produced trim warnings. For more information see https://aka.ms/il2104
Build succeeded with 2 warning(s) in 8.0s
Unhandled exception. MessagePack.MessagePackSerializationException: Failed to serialize MessagePackBug.ItemsRequest value.
---> System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.MissingMethodException: No parameterless constructor defined for type 'MessagePack.Formatters.ListFormatter`1[MessagePackBug.Item]'.
at System.ActivatorImplementation.CreateInstance(Type, BindingFlags, Binder, Object[], CultureInfo, Object[]) + 0x3b7
at MessagePack.Internal.DynamicGenericResolverGetFormatterHelper.GetFormatter(Type) + 0x546
at MessagePack.Resolvers.DynamicGenericResolver.FormatterCache`1..cctor() + 0x23
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb6
--- End of inner exception stack trace ---
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x13c
at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnGCStaticBase(StaticClassConstructionContext*, Object) + 0xd
at MessagePack.Resolvers.DynamicGenericResolver.GetFormatter[T]() + 0x11
at MessagePack.Resolvers.StandardResolver.FormatterCache`1..cctor() + 0xa4
at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb6
--- End of stack trace from previous location ---
at MessagePack.FormatterResolverExtensions.Throw(TypeInitializationException ex) + 0x21
at MessagePack.FormatterResolverExtensions.GetFormatterWithVerify[T](IFormatterResolver resolver) + 0x9e
at MessagePack.GeneratedMessagePackResolver.MessagePackBug.ItemsRequestFormatter.Serialize(MessagePackWriter&, ItemsRequest, MessagePackSerializerOptions) + 0x112
at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options) + 0xd3
--- End of inner exception stack trace ---
at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options) + 0x26e
at MessagePack.MessagePackSerializer.Serialize[T](T value, MessagePackSerializerOptions options, CancellationToken cancellationToken) + 0x19d
at MessagePackBug.Program.Main() + 0xfe
- Version used: MessagePack 3.1.2
- Runtime: .NET 9.0 with PublishAOT option
Additional context
Add any other context about the problem here.
- Linguagem predominante
- C#
- Estrelas
- 6.8k
- Forks
- 778
- Merge médio
- 22h 8min
- PRs com merge (30d)
- 2
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de MessagePack-CSharp/MessagePack-CSharp
-
SerializableMemberTypeAnalyzer throws AD0001 when any referenced assembly has an assembly-level attribute with a single array argumentTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 76/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
MessagePack-CSharp/MessagePack-CSharp#2276 · 2 comentários ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
MessagePack-CSharp/MessagePack-CSharp#2252 · 3 comentários ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
Todas as issues de MessagePack-CSharp/MessagePack-CSharp
Issues semelhantes
-
kind/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
unoplatform/uno#26555 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Listenarrs/Listenarr#1173 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
CactuseSecurity/firewall-orchestrator#5739 ·
Mantenedores costumam responder em até 1 dia
-
chore project-system small
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
vikramlearning/blazorbootstrap#1388 ·
Mantenedores costumam responder em até 1 dia