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

ConsoleApp sample server generates an exception with .NET 8.0 #42

Closed
PhilJollans opened this issue Dec 18, 2023 · 3 comments
Closed

ConsoleApp sample server generates an exception with .NET 8.0 #42

PhilJollans opened this issue Dec 18, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@PhilJollans
Copy link

Describe the bug

I have cloned the repo and tried to run the ConsoleApp sample.
By default, .NET 8.0 is selected.

When the client connects to the server it generates the exception:

ConsoleApp.MyMessage is not registered in resolver: MessagePack.Resolvers.StandardResolver

The complete message is

Client named_pipe_test_server_021d8e5e-1e5d-4d21-9abd-4cba84e491db is now connected!
Exception: MessagePack.MessagePackSerializationException: Failed to serialize System.Object value.
 ---> MessagePack.FormatterNotRegisteredException: ConsoleApp.MyMessage is not registered in resolver: MessagePack.Resolvers.StandardResolver
   at MessagePack.FormatterResolverExtensions.Throw(Type t, IFormatterResolver resolver)
   at MessagePack.FormatterResolverExtensions.GetFormatterDynamicWithVerify(IFormatterResolver resolver, Type type)
   at MessagePack.Formatters.DynamicObjectTypeFallbackFormatter.Serialize(MessagePackWriter& writer, Object value, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
   --- End of inner exception stack trace ---
   at MessagePack.MessagePackSerializer.Serialize[T](MessagePackWriter& writer, T value, MessagePackSerializerOptions options)
   at MessagePack.MessagePackSerializer.Serialize[T](T value, MessagePackSerializerOptions options, CancellationToken cancellationToken)
   at H.Formatters.MessagePackFormatter.SerializeInternal(Object obj) in C:\GitHub\H.Pipes\src\libs\H.Formatters.MessagePack\MessagePackFormatter.cs:line 12
   at H.Formatters.FormatterBase.Serialize(Object obj) in C:\GitHub\H.Pipes\src\libs\H.Formatters\FormatterBase.cs:line 28
   at H.Pipes.PipeConnection`1.WriteAsync(T value, CancellationToken cancellationToken) in C:\GitHub\H.Pipes\src\libs\H.Pipes\PipeConnection.cs:line 162
   at ConsoleApp.MyServer.<>c__DisplayClass1_0.<<RunAsync>b__0>d.MoveNext() in C:\GitHub\H.Pipes\src\samples\ConsoleApp\MyServer.cs:line 30

The error does not occur with .NET 6.0 or .NET 7.0

Steps to reproduce the bug

  1. In the project ConsoleApp, select .NET 8.0. This is the default.
  2. Compile the solution
  3. Start the ConsoleApp and enter SERVER
  4. Start the ConsoleApp and enter CLIENT
  5. At this point the client connects to the server and the server generates an exception

Expected behavior

No response

Screenshots

No response

NuGet package version

No response

Platform

Console

IDE

Visual Studio 2022

Additional context

No response

@PhilJollans PhilJollans added the bug Something isn't working label Dec 18, 2023
@HavenDV
Copy link
Owner

HavenDV commented Dec 18, 2023

I looked a little more into MessagePack, and it requires marking all types/properties with attributes, which is not entirely appropriate for Formatter by default.

[MessagePackObject]
public class MyClass
{
    // Key attributes take a serialization index (or string name)
    // The values must be unique and versioning has to be considered as well.
    // Keys are described in later sections in more detail.
    [Key(0)]
    public int Age { get; set; }

    [Key(1)]
    public string FirstName { get; set; }

    [Key(2)]
    public string LastName { get; set; }

    // All fields or properties that should not be serialized must be annotated with [IgnoreMember].
    [IgnoreMember]
    public string FullName { get { return FirstName + LastName; } }
}

So I changed this to SystemTextJsonFormatter for net8.0 and above

@PhilJollans
Copy link
Author

Great, thanks for looking into this problem so quickly.

@HavenDV
Copy link
Owner

HavenDV commented Dec 18, 2023

Now it's available in latest dev/preview version, I will release this as stable little later.

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

No branches or pull requests

2 participants