Use an object in the GAC

A

Andrea

I installed an assembly into the GAC, now I need to use it into a dll, but
I cannot simple reference it, since I'm developing in a local machine and
maybe that on the hosting provider the GAC isn't in the same local directory
and this teorically will broke the code. At least I think so, but I'm bot
sure since I cannot take a try.

Any Idea.

I thought to use the Assembly.Load using the reflection. Is this a suitable
way?

Thanks
Andre
 
K

Klaus H. Probst

I installed an assembly into the GAC, now I need to use it into a dll,
but I cannot simple reference it, since I'm developing in a local
machine and maybe that on the hosting provider the GAC isn't in the
same local directory and this teorically will broke the code. At least
I think so, but I'm bot sure since I cannot take a try.

Don't put it in the GAC. I doubt any hosting provider will let you
register an assembly in the local GAC at all anyway.
I thought to use the Assembly.Load using the reflection. Is this a
suitable way?

Well yes, but what's wrong with just referencing it normally? Is there any
reason why it must be in the GAC?
 
A

Andrea

Hello Klaus,
Well yes, but what's wrong with just referencing it normally? Is there
any reason why it must be in the GAC?

It's an object the hoster provide me for free and he has instlled in the GAC
to allow anyone to use. So it's not my own choice :(

Well ... suppose I've the object installed on my local machine, a demo, into
c:\windows\assembly ... .net knows that this is the GAC, now on the server
the GAC repository is in the d:\GAC ....

if I create a reference at my local repository, I suppose, the reference link
also the path, so my c:\windows\assembly, but when I'll deploy the code certainly
it
doesn't work, isn't it true?
 
K

Klaus H. Probst

It's an object the hoster provide me for free and he has instlled in
the GAC to allow anyone to use. So it's not my own choice :(

Oh, I see.
Well ... suppose I've the object installed on my local machine, a
demo, into c:\windows\assembly ... .net knows that this is the GAC,
now on the server the GAC repository is in the d:\GAC ....

Hopefully you didn't actually just copy the assembly to the directory? Use
gacutil.exe to install/uninstall assemblies in the GAC.
if I create a reference at my local repository, I suppose, the
reference link also the path, so my c:\windows\assembly, but when I'll
deploy the code certainly it
doesn't work, isn't it true?

Well, it will. Possibly =) The point of the GAC is that it doesn't matter
where in the machine it is physically located. So the fact that on the
server the GAC is actually on the D: drive should not matter. If you take
exactly the same assembly and install it on two different GACs on two
different machines the CLR should be resolve the types correctly when the
app domain needs it.
 
A

Andrea

Hello Klaus,
Hopefully you didn't actually just copy the assembly to the directory?
Use gacutil.exe to install/uninstall assemblies in the GAC.

Did it before post.
Well, it will. Possibly =) The point of the GAC is that it doesn't
matter where in the machine it is physically located. So the fact that
on the server the GAC is actually on the D: drive should not matter.
If you take exactly the same assembly and install it on two different
GACs on two different machines the CLR should be resolve the types
correctly when the app domain needs it.

So I was worrying for nothing. Just reference and stop :)
Sometimes the life is more easier ....

Thanks

Andrea
 
R

Raymond

For compile-time referencing you need another copy of the assembly
elsewhere outside GAC. Once you have it compiled, the program will
then use the one in GAC at run-time if you have no local copy. That's
why even MS assemblies which are in GAC have another copy in their
own folder in WinNT/Microsoft.NET.
 
A

Andrea

Hello Klaus,

But there is one thing that I don't understand. Go to add reference, choose
browse, select c:\windows\assembly, I
select my GAC component, but it doesn't allow me to select.
It asks for the file name. I supply it, VS says it doesn't exist. Should
I select file from the gac, or from local path and
then if it will be in the GAC it will used without problems?

Andre
 
A

Andrea

Hello Klaus,
Never select assemblies from under the GAC =)

The problem is the way VS.NET enumerates assemblies. It doesn't do it
off the GAC. Take a look at this:

http://support.microsoft.com/default.aspx?scid=kb;en-us;306149

Well I go to the folder specified, and the hive of the component installed
by the GACutil is
there ... so according to the article is right that I can see the component .

So selecting it, since it's correctly registered in the GAC, means that VS
when compile doesn't
copy it into the bin folder and well I'll deploy my code I don't have problems.

Is it right?

Andre
 
S

S. Justin Gengo

Raymond,

Just to clarify (I believe I'm right about this) at run-time the gac will be
checked for the assembly based on version first no matter what. Even if the
assembly exists in the bin folder also the one in GAC is the one that will
be used.

Regards,

Justin
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top