I’m working on a new build for my network library and I reworked it to have packet headers that specify the type of the object that is sent, and when all the data is received it deserialize it into the correct type. It works with any built in type I have tried, but the problem arises when the the assembly of the class is different between the sender and receiver. I found a solution that works well with some base types, but if I send an array of any sort of the object, my code cannot find the type. Anyone have any solutions?

If [your object].gettype() == typeof(known object)…
Is that what you mean?

Whoops, I accidentally commented this on my post instead of replying. I’ll leave that there but I’m gonna repeat that here

What I’ve tried is basically color is a test class I wrote in two different programs/assemblies
color[,] image; string name = image.GetType().Name;
//send image and name over socket
Type type = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .FirstOrDefault(x => x.Name == name);
object obj = JsonConvert.DeserializeObject(json, type); color is a defined type in a namespace but color[,] is not (to my knowledge of how the compiled stuff works). I’m trying to figure out how to get Type color[,]
So instead of using GetTypes from the GetAssemblies. You want to use Type.GetType(name) instead.

Also if this is for networking, you most likely want to use the Assembly Qualified Name instead of just plain Type Name. And possibly remove the Assembly Version for compatibility.

Also if this is for networking, you most likely want to use the Assembly Qualified Name instead of just plain Type Name. And possibly remove the Assembly Version for compatibility

I’m trying to get that to work, but the fully qualified name is different between apps if the client app isn’t the same as the server app. I have a solution that does that part well for the tests I have done, but I’m trying to find how to create a type that isn’t explicitly defined in the assembly.
Ex. UserDefinedType is defined with a few property’s and methods, but a UserDefinedType[,,] isn’t.

What I’ve tried is basically color is a test class I wrote in two different programs/assemblies
color[,] image; string name = image.GetType().Name;
//send image and name over socket
Type type = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .FirstOrDefault(x => x.Name == name);
object obj = JsonConvert.DeserializeObject(json, type); color is a defined type in a namespace but color[,] is not (to my knowledge of how the compiled stuff works). I’m trying to figure out how to get Type color[,]
Color[,] is not a type in itself, so you won’t pick it up through GetTypes().

It is a type (not sure what the official documentation calls it) that is built off an existing type.
Aside from passing the type over the socket, you also need to pass information about whether it is an array, and if so what rank/dimensionality.

Then you would have to construct the array type with Type.MakeArrayType using that information.
type will be System.Drawing.Color[,]

Working with Generic lists is another challenge, but basically you have to create the type as well using the List<> type.
Also, why not use protobuf, or some other preexisting binary serialization method?

source