Dll conflict

Q

qiucx

If i want to develope one class library and it depends two dll files named
DependencyA, DependencyB. Meanwhile, DependencyA depend on DependencyC with
version 1.0, DependencyB depend on DependencyC with version 2.0.

My question is which version of DependencyC i should use? Version1.0 dll or
version2.0 dll file?

question2:
When i add the source code of DependencyC, i get error during compiling:

Error 5 The type 'xxxx' is defined in an assembly that is not referenced.
You must add a reference to assembly 'DependencyC, Version=1.0.0.0,
Culture=neutral,
PublicKeyToken=b7567367622062c6'. D:\LearnWCF\test\test\Helper.cs 125 17 test

I have added the source code, i do not know how to solve this problem.

Thanks in advanced.
 
M

Morten Wennevik [C# MVP]

Hi,

Any single appdomain can only reference one version of an assembly, and
usually the later version takes precedence. To be able to use different
versions in the same application you need to create separate AppDomain
objects that internally reference only one version of DependencyC. The
drawback to this approach is that AppDomains are entirely isolated and the
main domain needs to communicate using .net remoting with its subdomains. To
get intellisense support all objects passed through the domain borders needs
to inherit MarshalAsRefObject and will be garbage collected when their lease
time runs out and not when you no longer reference the object.

A simple example on how you can do it. Create a class library MyLibrary
containing a class MyClass which inherits MarshalAsRefObject as well as
implementing an interface IMyClass defined in a separate class library which
is referenced by both MyLibrary as well as the main application. If you put
all MyClass files in a folder called Folder1 you can load this library and
all its dependencies using the following piece of code:

Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
Evidence securityInfo = new Evidence(baseEvidence);

AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = "Folder1";
AppDomain domain = AppDomain.CreateDomain("MyDomain", securityInfo, info);
IMyClass myClass =
(IBeregner)domain.CreateInstanceFromAndUnwrap("Folder1\\MyLibrary.dll",
"MyNamespace.MyClass");

IResult = myClass.DoSomething();
 
M

Morten Wennevik [C# MVP]

Hi,

Any single appdomain can only reference one version of an assembly, and
usually the later version takes precedence. To be able to use different
versions in the same application you need to create separate AppDomain
objects that internally reference only one version of DependencyC. The
drawback to this approach is that AppDomains are entirely isolated and the
main domain needs to communicate using .net remoting with its subdomains. To
get intellisense support all objects passed through the domain borders needs
to inherit MarshalAsRefObject and will be garbage collected when their lease
time runs out and not when you no longer reference the object.

A simple example on how you can do it. Create a class library MyLibrary
containing a class MyClass which inherits MarshalAsRefObject as well as
implementing an interface IMyClass defined in a separate class library which
is referenced by both MyLibrary as well as the main application. If you put
all MyClass files in a folder called Folder1 you can load this library and
all its dependencies using the following piece of code:

Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
Evidence securityInfo = new Evidence(baseEvidence);

AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = "Folder1";
AppDomain domain = AppDomain.CreateDomain("MyDomain", securityInfo, info);
IMyClass myClass =
(IBeregner)domain.CreateInstanceFromAndUnwrap("Folder1\\MyLibrary.dll",
"MyNamespace.MyClass");

IResult = myClass.DoSomething();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top