1

Say we define plugin interface in assembly A.

public class PluginData { public string Data { get; set; } }
public interface IPlugin { public PluginData Get(); }

We have a lot of plugins using it. Then, we change plugin interface to add one more method, now plugin interface assembly becomes v1.1.

public class PluginData { public string Data { get; set; } }
public interface IPlugin
{
   public PluginData Get(); 
   public void Process(PluginData data);
}

Now, is there a way to do

var data = new PluginV10().Get();
new PluginV11().Process(data);

?

The only solutions I see now is to marshal data manually by serializing/deserializing it, having custom from/to XML methods, invoked using reflection, etc.

queen3
  • 15,333
  • 8
  • 64
  • 119
  • As for me your code snippet is fine as long both `Get()/Process()` methods references the same `PluginData` class, or what is the problem with it? – sll Oct 19 '11 at 09:57
  • The 'assembly' tag is for low level programming, not for .NET assemblies. – harold Oct 19 '11 at 11:24
  • The problem with code snippet is that PluginData types are incompatible. PluginV11 will expect PluginData v11 version, and/or vice versa. Types from different assembly versions are not compatible. E.g. see http://blogs.msdn.com/b/thottams/archive/2007/04/11/two-versions-of-an-assembly-in-an-appdomain.aspx – queen3 Oct 19 '11 at 12:20

1 Answers1

0

All You need to do is to define type PluginData in one place only. This means, that if both versions of your interface and the rest of code reference to assembly A type PluginData,everything will work ok.

EDIT:

If IPluginDataV2 does not inherit from IPluginDataV1 then all I can think of is to save PluginDataV1 instance as xml and then populate IPluginDataV2 with data from XML. Guess You can try with builtin XML serialization but You might encounter problem with new non-nullable properties that don't exist in PluginDataV1. Also, all other XML serialization limitations apply, like serialization only works for public properties and fields.

If You decide to go with XML serialization You might want to take a look at excellent thread: XML serialization gotchas.

EDIT #2: Actually, I believe You gave exact answer in the last sentence of your question already.

Community
  • 1
  • 1
Filip Popović
  • 2,637
  • 3
  • 18
  • 18