I am compiling code on the fly and it has been working great; however
I recently made a change to one of my external class libraries that I
am
referencing and the version changed, now I have 2 versions of the
component in the GAC.
How do you specify which version of the component you want to use in
GAC?
I know I can hard code a path to it and not put it in the GAC - but I
would really prefer the GAC.
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Web.Services.dll");
cp.ReferencedAssemblies.Add("MyDll.dll") // WHICH VERSION???!!!!
Can you do this?
cp.ReferencedAssemblies.Add("MyDll, Version=1.0.4500.0,
Culture=neutral, PublicKeyToken=b87a5e561734a093")
(I just made up the PublicKeyToken...)
Peter Koen - 09 Oct 2003 22:16 GMT
> I am compiling code on the fly and it has been working great; however
> I recently made a change to one of my external class libraries that I
[quoted text clipped - 19 lines]
>
> (I just made up the PublicKeyToken...)
Afaik, you could do something like this:
Assembly a = Assembly.Load( .... here you can give all the details ...)
cp.ReferencedAssemblies.Add(a);

Signature
best regards
Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Matt - 10 Oct 2003 12:49 GMT
This won't work, ReferencedAssemblies is a string collection.
There doesn't seem to be an overload for an Assembly -
ReferencedAssemblies.Add(<string>)
Peter Koen - 10 Oct 2003 13:50 GMT
> This won't work, ReferencedAssemblies is a string collection.
> There doesn't seem to be an overload for an Assembly -
>
> ReferencedAssemblies.Add(<string>)
but with assembly.ToString() you should get an exact representation of that
assembly incl. version.

Signature
best regards
Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Matt - 13 Oct 2003 21:19 GMT
Yes, I see what you mean. Question though; I've read other threads
where other developers want to stay away from Assembly.Load() because
it loads that .dll into memory and doesn't release it until the
application completes.
My "compiler service" (which is a Server that I run as a service)
never ends. So it would then never release that .dll. I see that as
a potential problem.
Thoughts?
Peter Koen - 13 Oct 2003 22:03 GMT
> Yes, I see what you mean. Question though; I've read other threads
> where other developers want to stay away from Assembly.Load() because
[quoted text clipped - 6 lines]
>
> Thoughts?
oh well. indeed than that'S a problem.
although if you are using frequently the same dll's then this can be a
feature: they wouldn't be loaded for a second or third time, there will
be a cached, already loaded version that can be used.
if you still want to unload your assemblies you can open a new appdomain,
load the assembly there and then close that appdomain. that would remove
the assembly from memory.
or you just stick to identifying the version of your assemblies manually
without loading them.
or another possibility: you could use the unmanaged metadata api to
localize these infos in the assemblies without loading them. but then you
would have lotsa unmanaged code with lots of interop calls. that'S hard
to code and also quite a performance loss because every managed<->
unmanaged call has to be marshaled.

Signature
best regards
Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Guru Prasad - 10 Oct 2003 01:22 GMT
Or for additional flexibility ( i.e your assembly version may change later
... ) you may want to keep the code as it is, but add "binding redirects" to
your app config file along with the "qualify assembly" element.
Works for normal .NET/ASP.NET apps; should work with dynamic compilation as
well i think.
> I am compiling code on the fly and it has been working great; however
> I recently made a change to one of my external class libraries that I
[quoted text clipped - 19 lines]
>
> (I just made up the PublicKeyToken...)