jacqueskang/IpcServiceFramework

Calling .NET 4.x hosted service from .NET core client serialization fails

Closed this issue · 2 comments

Describe the bug
Seems that calling a full .net hosted service from a .net core client can't work with a serialization exception

To Reproduce

  1. Create a full .net hosted service using named pipes (but I believe same occurs with a tcp channel)
  2. Create a .net core (tested 3.1) client using named pipes
  3. Running the client an exception occurs:

JKang.IpcServiceFramework.IpcFaultException: Failed to deserialize request. ---> JKang.IpcServiceFramework.IpcSerializationException: Failed to deserialize IPC message ---> Newtonsoft.Json.JsonSerializationException: Error converting value "System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" to type 'System.Type'. Path 'ParameterTypes[0]', line 1, position 481. ---> System.ArgumentException: Could not cast or convert from System.String to System.Type.
in Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
in Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
--- Fine della traccia dello stack dell'eccezione interna ---
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
in Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
in Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
in Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
in Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
in JKang.IpcServiceFramework.Services.DefaultIpcMessageSerializer.Deserialize[T](Byte[] binary)
--- Fine della traccia dello stack dell'eccezione interna ---
in JKang.IpcServiceFramework.Services.DefaultIpcMessageSerializer.Deserialize[T](Byte[] binary)
in JKang.IpcServiceFramework.Services.DefaultIpcMessageSerializer.DeserializeRequest(Byte[] binary)
in JKang.IpcServiceFramework.IO.IpcReader.d__5.MoveNext()
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
in JKang.IpcServiceFramework.Hosting.IpcEndpoint1.<ProcessAsync>d__7.MoveNext() --- Fine della traccia dello stack dell'eccezione interna --- in JKang.IpcServiceFramework.Hosting.IpcEndpoint1.d__7.MoveNext()

Expected behavior
The call should just work

This is the definition of the service:

    public class HostRectangle
    {
        public int Left { get; set; }
        public int Top { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
    }

    public class ConnectionSettings
    {
        public string Server { get; set; }

        public string Username { get; set; }

        public string Password { get; set; }

        public string Domain { get; set; }
    }

    public interface IRdpHost
    {
        void Create(int parentHandle, HostRectangle hostRect, ConnectionSettings connectionSettings);

        void ResizeWindow(HostRectangle hostRect);

        void CloseHost();
    }

I don't know if this is expected behavior?

@adospace I think this is as expected because assembly names are different between .NET 4 and .NET core (mscorlib vs. System.Private.CoreLib). Maybe you can implement a customized IIpcMessageSerializer to resolve the problem.

#167 should resolve the issue. I'm closing for now and feel free to reopen if necessary.