0

I have followed this article to start using MessagePack in my asp.net core 3.1 application but it's not working due to the following error message:

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'MessagePack.Resolvers.ContractlessStandardResolver' to 'MessagePack.MessagePackSerializerOptions' Gateway C:\Developments\POC\Gateway\Startup.cs 33 Active

enter image description here

What is another alternative or solution to fix this compile problem?

Arash
  • 3,628
  • 5
  • 46
  • 70
  • It would really be helpful if you copy paste the code here and not an image. – Rod Talingting Jul 06 '20 at 21:30
  • Try figuring out what parameters the constructor of `MessagePackOutputFormatter` takes and fill it in. It seems like it needs some sort of Options class of type `MessagePackSerializerOptions`. Try creating that one first and the supply the resolver. – Michael Jul 06 '20 at 22:29

1 Answers1

1

As @Michael said, what is needed behind MessagePackOutputFormatter is the MessagePackSerializerOptions type, and the current error occurs because the type is ContractlessStandardResolver, which is not consistent.

Therefore, you only need to modify the code as follows:

 services.AddMvc().AddMvcOptions(option =>
            {
                option.OutputFormatters.Clear();
                option.OutputFormatters.Add(new MessagePackOutputFormatter(ContractlessStandardResolver.Options));
                option.InputFormatters.Clear();
                option.InputFormatters.Add(new MessagePackInputFormatter(ContractlessStandardResolver.Options));
            })
   .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
LouraQ
  • 6,443
  • 2
  • 6
  • 16
  • I made the changed that you suggested but I get the following error message from the server: 'Invalid response code for http request response NotAcceptable: Not Acceptable'. The following code snippet shows how the client prepares the payload string and the header to submit: var httpContent = new StringContent(payload, Encoding.UTF8, "application/x-msgpack"); – Arash Jul 07 '20 at 12:41