0

What is the best way for passing a "non-serialized" object to another appdomain without Serilization/Deserialization ?

More detail: I'm going to invoke a function (from external assembly/plugin) in new appdomain and pass the result to main appdomain (main program). but (unfortunately) the result type is not serializable and therefore i faced to SerializationException

limitations:

the non-serialized type is in external assembly/dll. So i cannot mark it as serializable with attribute.

1 Answers1

1

If you want to pass it through the remoting infrastructure it must be either by ref or serializable.

Since this type is neither you have limited options:

  1. Perform the processing in the remote app domain.
  2. Perform custom serialization to transfer the data you want (not the object). For example, copy the values to a serializable DTO class or use a serializer library.
usr
  • 168,620
  • 35
  • 240
  • 369
  • the second option seems to be more complicated (am i right?)... but can you give more info (link) about the first option? – user11448245 May 09 '19 at 09:08
  • For (1) you can execute in the remote app domain though AppDomain.DoCallback or through writing a custom MarshalByRefObject, creating an instance in the remote domain and calling something on it. – usr May 09 '19 at 09:30
  • (2) could be very easy. Nothing really prevents these objects from being serialized. The Serializable attribute is an artifical restriction. You can use a binary serializer library and just serialize anything. It might work or not depending on how the classes are written. – usr May 09 '19 at 09:31
  • thanks. for (1), i found this link but it seems that there is a problem with Execute method. could you take a look at that (or give me another sample)? [link](https://stackoverflow.com/questions/50776377/c-sharp-loading-a-dll-byte-array-into-a-different-appdomain-throws-system-io-fil/) – user11448245 May 11 '19 at 07:10
  • Not sure what Execute method you are speaking of. It has been 10 years since I worked with AppDomains so I do no longer remember how exactly to create an instance in a remote AppDomain. But it was not that hard. I'm sure you can find material on how to do that. This seems to demonstrate how to do it: https://stackoverflow.com/questions/1767439/passing-data-across-appdomains-with-marshalbyrefobject – usr May 11 '19 at 07:47