Allow to reference to any version of assembly during compiling

A

Andrus

VCSE 2005 .NET 2 WinForms

I created assembly at runtime and added mydll.dll reference to it.
mydll.dll is in applicatino startup directory.
When I change mydl.dll to never version, this assembly is not loaded
anymore: error occurs which says that created assembly requires specific
version of mydll.dll

How to add assembly reference at runtime which does not require specific
version ?

Andrus.

My code:

void CompileAssembly(string code, string assemblyName) {

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters compilerParameters = new CompilerParameters();
CompilerResults result =
provider.CompileAssemblyFromSource(compilerParameters, code);
// this causes created assembly to require specific version of mydll
// How to allow to use any version on mydll.dll file ?
compilerParameters.ReferencedAssemblies.Add("mydll.dll");
compilerParameters.GenerateInMemory = false;
compilerParameters.OutputAssembly = assemblyName;
CompilerResults compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, code);
}
 
F

Frans Bouma [C# MVP]

Andrus said:
VCSE 2005 .NET 2 WinForms

I created assembly at runtime and added mydll.dll reference to it.
mydll.dll is in applicatino startup directory.
When I change mydl.dll to never version, this assembly is not loaded
anymore: error occurs which says that created assembly requires
specific version of mydll.dll

How to add assembly reference at runtime which does not require
specific version ?

Andrus.

My code:

void CompileAssembly(string code, string assemblyName) {

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters compilerParameters = new CompilerParameters();
CompilerResults result =
provider.CompileAssemblyFromSource(compilerParameters, code);
// this causes created assembly to require specific version of mydll
// How to allow to use any version on mydll.dll file ?
compilerParameters.ReferencedAssemblies.Add("mydll.dll");
compilerParameters.GenerateInMemory = false;
compilerParameters.OutputAssembly = assemblyName;
CompilerResults compilerResults =
provider.CompileAssemblyFromSource(compilerParameters, code);
}

Did you sign mydll.dll ? If so, be sure the assembly version attribute
contains a real version, so not 1.0.*.* (which changes with every
build!) but 1.0.0.0 and version only when you need to (i.e. when the
interface breaks), which means you have to re-compile the clients
anyway.

FB


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
A

Andrus

Frans,
Did you sign mydll.dll ? If so, be sure the assembly version attribute
contains a real version, so not 1.0.*.* (which changes with every
build!) but 1.0.0.0 and version only when you need to (i.e. when the
interface breaks), which means you have to re-compile the clients
anyway.

thank you.

The file mydll.dll which I reference is produced by external vendor.
I have no control over its versioning or signing.

So I must reference to any version of this file from my dynamically created
assembly.

Anyh idea how to implement this ?

Andrus.
 
F

Frans Bouma [C# MVP]

Andrus said:
Frans,


thank you.

The file mydll.dll which I reference is produced by external vendor.
I have no control over its versioning or signing.

So I must reference to any version of this file from my dynamically
created assembly.

Anyh idea how to implement this ?

This vendor, don't they ship a policy file with thier assembly?

Is the mydll signed (does it have a strong name?)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
A

Andrus

The file mydll.dll which I reference is produced by external vendor.
This vendor, don't they ship a policy file with thier assembly?

I have the following files (mydll is actually Castle.ActiveRecord) :

14.10.2007 16:55 192 512 Castle.ActiveRecord.dll
14.10.2007 16:55 658 944 Castle.ActiveRecord.pdb
14.10.2007 16:55 459 779 Castle.ActiveRecord.xml

So I think I don't have policy file (I have no idea what is policy file)
Is the mydll signed (does it have a strong name?)

Solution explorer shows the following properties for Castle.ActiveRecord.dll

Strong Name true
Version 1.0.3.0

So it is signed.

Andrus.
 
F

Frans Bouma [C# MVP]

Andrus said:
I have the following files (mydll is actually Castle.ActiveRecord) :

14.10.2007 16:55 192 512 Castle.ActiveRecord.dll
14.10.2007 16:55 658 944 Castle.ActiveRecord.pdb
14.10.2007 16:55 459 779 Castle.ActiveRecord.xml

So I think I don't have policy file (I have no idea what is policy
file)


Solution explorer shows the following properties for
Castle.ActiveRecord.dll

Strong Name true
Version 1.0.3.0

So it is signed.

But if you reference that dll in YOUR application, every build of your
application shoudl be able to load that particular dll with that
particular version.

If you then place 1.0.4.0 in the bin folder, you won't be able to load
that file. But, if you add an assembly redirect in your application's
config file to redirect bindings to 1.0.3.0 to 1.0.4.0, you will be
able to load that file. Of course, if 1.0.4.0 has newer interfaces and
breaking changes, it's not wise to do so, but you can.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
A

Andrus

But if you reference that dll in YOUR application, every build of your
application shoudl be able to load that particular dll with that
particular version.

Yes, I can rebuild my solution and this works OK.
However the issue occurs in customer sites when I upgrade referenced dll
file but my dynamically generated assembly contains reference to old
version.
If you then place 1.0.4.0 in the bin folder, you won't be able to load
that file. But, if you add an assembly redirect in your application's
config file to redirect bindings to 1.0.3.0 to 1.0.4.0, you will be
able to load that file. Of course, if 1.0.4.0 has newer interfaces and
breaking changes, it's not wise to do so, but you can.

As I understand at application startup I need to check assembly version and
dynamically update app.config file by adding assembly redirect.

Vista UAC prevents my application changing app.config file.
How to create dynamic assembly redirect without writing to restricted
directories ?
Or is there better solution ?

Andrus.
 

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