当前位置: 动力学知识库 > 问答 > 编程问答 >

.net - Managing multiple DLLs with same namespace in a C# project

问题描述:

Language: C#

IDE: Visual Studio 2010

.Net Version: 4.0

Client side: Silverlight 5

We have an application that stores a serialized version of a range of UI objects in a DB schema. For each UI object in this schema, we serialise the object, namespace and version that it pertains to, so -

<UIObject>MyCompany.MyProject.MyControlName, 1.0.0.0</UIObject>

Now say we want to make a breaking change in one of the object DLLs but want to maintain backwards compatibility - what we'd like to do is output something like the following in newer versions of the XML -

<UIObject>MyCompany.MyProject.MyControlName, 2.0.0.0</UIObject>

Now, we instantiate these objects in a parser within our app, and this parser uses reflection code similar to the following:

 Assembly asm = Assembly.LoadFrom(assembly);

Type classtype = asm.GetType(type, true, false);

object dynamicObject = Activator.CreateInstance(classtype);

MethodInfo invokedMethod = classtype.GetMethod(method);

return invokedMethod.Invoke(dynamicObject,parameters);

My question what's the best way to reference two different DLLs (with the same namespaces if possible) so that the code that uses reflection can easily instantiate different objects depending on the version in the XML?

What I've looked at so far:

  1. Using the GAC - doesnt seem to work
  2. Creating an "extern alias" for both DLL's - but i cant figure out how to use this with reflection
  3. Referencing both DLL's in VS - obviously wont work because of the conflicting namespaces - ambiguous references being thrown up

I can of course start splitting out code into different project but would like to avoid code duplication as much as possible... so that namespaces become:

<UIObject>MyCompany.MyProject.v1.0.0.0.MyControlName</UIObject>

Any suggestions?

分享给朋友:
您可能感兴趣的文章:
随机阅读: