Search code examples
c#.net.net-standardakka.net

.Net Standard 4.7.1 Could not load System.Private.CoreLib during serialization


I'm working on migrating most of my project to .Net Standard 2.0.

Last part of the project in .net standard 4.7.1 is a WCF front end. This executable communicate with a .net core application throught a library Akka.net by ClientServiceReceptionist.

Network communication between application by akka.net work. Except when an it try to serialize a ReadOnlyCollection.

In this case the system try to load a "System.Private.CoreLib.dll" that is not available.

enter image description here

I readed many issues with .net 4.6 using .net standard 2.0 libraries that must have been corrected in 4.7.1. I pass from package.config to PackageReference.

I tryed to used NewtonSoft as a serializer in place of Hyperion without progress.

Does anyone have an idea, a solution ?

Edit : 07-05-2018

enter image description here

The issue is throw in the WCF Entry Points when i sent a ClusterClient.Send object throught the ClusterClientReceptionist.

The object sent contains only boolean, string, Guid and array of string properties.

Edit 08-05-2018

The object sent look like this :

{
  (string) "Path": "/user/ProcessOrderWorkflow",
  "Message": {
    "Order": {
      "Data": {
        (string)"Sentence": "i love my name",
        "Options": {
            (boolean)"Simplify" : true,
            (IReadOnlyCollection<string>) LanguageAffinity : [ "FR", "EN" ]
        }
      },
      "OrderQuery": {
        "Verb": {
          (string)"Verb": "Extract"
        },
        "Arguments": [
          {
            (string)"Argument": "Sentence"
          },
          {
            (string)"Argument": "Meaning"
          }
        ]
      },
      (Guid)"ProcessId": "0bfef4a5-c8a4-4816-81d1-6f7bf1477f65"
    },
    (string)"ReturnTypeFullName": "Viki.Api.Server.Data.SentenceMeaningMsg,, Viki.Api.Server.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
  },
  (boolean)"LocalAffinity": false
}

Each of the object used in the hierachi is builded using the constructor. All the properties are in readonly.

I tryed to serialize and deserialize the result on the WCF part before it's sent and it works.

var serializer = this._system.Serialization.FindSerializerFor(result);
var bytes = serializer.ToBinary(result);
var data = serializer.FromBinary(bytes, result.GetType());

The strange think is that it try to deserialize the object in the WCF part where it is sent and not in the LightHouse where the element should be received and transfert to a agent for processing.


Solution

  • So this is what I thought the issue might be... The problem is that transmitting serialized content between a .NET Core application and a .NET Framework application using a polymorphic serializer like JSON.NET or Hyperion is an unsupported operation in Akka.NET at least, but also in any other runtime where the users uses CLR types as the wire format of the messages.

    A brief explanation as to why we don't support this in Akka.NET, from the v1.3.0 release notes:

    As a side note: Akka.NET on .NET 4.5 is not wire compatible with Akka.NET on .NET Core; this is due to fundamental changes made to the base types in the CLR on .NET Core. It's a common problem facing many different serializers and networking libraries in .NET at the moment. You can use a X-plat serializer we've developed here: #2947 - please comment on that thread if you're considering building hybrid .NET and .NET Core clusters.

    The "fundamental changes" in this case being that the namespaces for types like string are different on .NET 4.* and .NET Core, thus a polymorphic serializer that doesn't account for those differences will throw this type of exception.

    We do have a workaround available here if you'd like to use it:

    https://github.com/akkadotnet/akka.net/pull/2947

    You'll need to register that serializer compat layer with JSON.NET inside Lighthouse and your .NET 4.7.1 apps.