HighTechTalks DotNet Forums  

Why are assemblies loading from the GAC?

Dotnet Framework microsoft.public.dotnet.framework


Discuss Why are assemblies loading from the GAC? in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Schemer
 
Posts: n/a

Default Why are assemblies loading from the GAC? - 06-20-2006 , 12:25 PM






Hello,

I'm building a project in VisStudio 2005. I have .Net component that put
several assemblies in the GAC. However, I want to test local versions of
those assemblies. In my VisStudio2005 project I explicitly reference the
assemblies in a particular directory, and set CopyLocal=TRUE.

When I start my project in the debugger, I see that the assemblies I'd like
to debug aren't getting loaded; instead, the version in the GAC is.

What's going on?
(I'm pretty sure this I used to be able to debug my local dlls.)

Thanks for any help.



Reply With Quote
  #2  
Old   
Michael Nemtsev
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-20-2006 , 02:22 PM






Hello Schemer,

Because CLR start looking for assebmly from the GAC.
To override this behaviour you need to redirect it in the config file to
the version in you private folder.
Seems that u need specify assemblyBinding tag in config


S> I'm building a project in VisStudio 2005. I have .Net component that
S> put several assemblies in the GAC. However, I want to test local
S> versions of those assemblies. In my VisStudio2005 project I
S> explicitly reference the assemblies in a particular directory, and
S> set CopyLocal=TRUE.
S>
S> When I start my project in the debugger, I see that the assemblies
S> I'd like to debug aren't getting loaded; instead, the version in the
S> GAC is.
S>
S> What's going on?
S> (I'm pretty sure this I used to be able to debug my local dlls.)
S> Thanks for any help.
S>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche



Reply With Quote
  #3  
Old   
Schemer
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-20-2006 , 02:51 PM



Thanks for the reply.
If you mean the .csproj file, I already have this:
<Reference Include="Digger.Backhoe, Version=4.0.0.394, Culture=neutral,
PublicKeyToken=93e298a0f6b95eb1">
<HintPath>..\..\..\..\exports\duw32\Digger.Backhoe .dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>

Or is there another configuration file I should look at?

"Michael Nemtsev" <nemtsev (AT) msn (DOT) com> wrote

Quote:
Hello Schemer,

Because CLR start looking for assebmly from the GAC.
To override this behaviour you need to redirect it in the config file to
the version in you private folder.
Seems that u need specify assemblyBinding tag in config


S> I'm building a project in VisStudio 2005. I have .Net component that
S> put several assemblies in the GAC. However, I want to test local
S> versions of those assemblies. In my VisStudio2005 project I
S> explicitly reference the assemblies in a particular directory, and
S> set CopyLocal=TRUE.
S> S> When I start my project in the debugger, I see that the assemblies
S> I'd like to debug aren't getting loaded; instead, the version in the
S> GAC is.
S> S> What's going on?
S> (I'm pretty sure this I used to be able to debug my local dlls.)
S> Thanks for any help.
S> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche





Reply With Quote
  #4  
Old   
Michael Nemtsev
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-20-2006 , 03:00 PM



Hello Schemer,

Your.exe.config file

if it missed, add in from the project. Add New->App.config

S> Thanks for the reply.
S> If you mean the .csproj file, I already have this:
S> <Reference Include="Digger.Backhoe, Version=4.0.0.394,
S> Culture=neutral,
S> PublicKeyToken=93e298a0f6b95eb1">
S>
S> <HintPath>..\..\..\..\exports\duw32\Digger.Backhoe .dll</HintPath>
S> <SpecificVersion>False</SpecificVersion>
S> <Private>True</Private>
S> </Reference>
S> Or is there another configuration file I should look at?
S>
S> "Michael Nemtsev" <nemtsev (AT) msn (DOT) com> wrote in message
S> news:1799a79b399b918c862cf37167639 (AT) msnews (DOT) microsoft.com...
S>
Quote:
Hello Schemer,

Because CLR start looking for assebmly from the GAC.
To override this behaviour you need to redirect it in the config file
to
the version in you private folder.
Seems that u need specify assemblyBinding tag in config
S> I'm building a project in VisStudio 2005. I have .Net component
that
S> put several assemblies in the GAC. However, I want to test local
S> versions of those assemblies. In my VisStudio2005 project I
S> explicitly reference the assemblies in a particular directory, and
S> set CopyLocal=TRUE.
S> S> When I start my project in the debugger, I see that the
assemblies
S> I'd like to debug aren't getting loaded; instead, the version in
the
S> GAC is.
S> S> What's going on?
S> (I'm pretty sure this I used to be able to debug my local dlls.)
S> Thanks for any help.
S> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour
"At times one remains faithful to a cause only because its opponents
do not cease to be insipid." (c) Friedrich Nietzsche

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche




Reply With Quote
  #5  
Old   
Marina Levit [MVP]
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-20-2006 , 03:01 PM



No, he is talking about the application configuration file. The project
file is only used for visual studio so it knows what files are part of your
project, etc.

The CopyLocal property is just to tell visual studio whether or not to copy
the file over to wherever the DLL or executable is being compiled to. It is
completely unrelated to anything that happens at runtime, and again, is only
for visual studio.

"Schemer" <jumper (AT) nospam (DOT) nospam> wrote

Quote:
Thanks for the reply.
If you mean the .csproj file, I already have this:
Reference Include="Digger.Backhoe, Version=4.0.0.394, Culture=neutral,
PublicKeyToken=93e298a0f6b95eb1"
HintPath>..\..\..\..\exports\duw32\Digger.Backhoe. dll</HintPath
SpecificVersion>False</SpecificVersion
Private>True</Private
/Reference

Or is there another configuration file I should look at?

"Michael Nemtsev" <nemtsev (AT) msn (DOT) com> wrote in message
news:1799a79b399b918c862cf37167639 (AT) msnews (DOT) microsoft.com...
Hello Schemer,

Because CLR start looking for assebmly from the GAC.
To override this behaviour you need to redirect it in the config file to
the version in you private folder.
Seems that u need specify assemblyBinding tag in config


S> I'm building a project in VisStudio 2005. I have .Net component that
S> put several assemblies in the GAC. However, I want to test local
S> versions of those assemblies. In my VisStudio2005 project I
S> explicitly reference the assemblies in a particular directory, and
S> set CopyLocal=TRUE.
S> S> When I start my project in the debugger, I see that the assemblies
S> I'd like to debug aren't getting loaded; instead, the version in the
S> GAC is.
S> S> What's going on?
S> (I'm pretty sure this I used to be able to debug my local dlls.)
S> Thanks for any help.
S> ---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche







Reply With Quote
  #6  
Old   
AT
 
Posts: n/a

Default RE: Why are assemblies loading from the GAC? - 06-21-2006 , 06:18 AM



Hi Schemer,

Thanks for your post!

Yes, I can reproduce out this behavior. CLR will always load the signed
assembly from GAC not your local copy of assembly.

Actually, this behavior is defined by the design of CLR probing logic,
please refer to the article below:
"How the Runtime Locates Assemblies"
http://msdn2.microsoft.com/en-us/library/yx7xezcf.aspx

As you can see the CLR runtime will always check GAC before private
folders. This behavior can not be changed in .Net1.1. However, in .Net2.0,
you can override the probing logic by hosting CLR, please refer to our
Fusion developer Junfeng Zhang's blog below:
"Override CLR Assembly Probing Logic ---
IHostAssemblyManager/IHostAssemblyStore"
http://blogs.msdn.com/junfeng/archiv...27/561775.aspx

Anyway, in your scenario, I think the simplest workaround is uninstalling
the assembly from GAC.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #7  
Old   
Schemer
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-21-2006 , 07:27 AM



Thanks for all the replies.

It appears that when my local dlls had the same version number as those in
the GAC, the assemblies in the GAC were loaded (even when the local dlls
were referenced specifically).
When my local assemblies have a different version number, they get loaded
and I can debug them.

"Schemer" <jumper (AT) nospam (DOT) nospam> wrote

Quote:
Hello,

I'm building a project in VisStudio 2005. I have .Net component that put
several assemblies in the GAC. However, I want to test local versions of
those assemblies. In my VisStudio2005 project I explicitly reference the
assemblies in a particular directory, and set CopyLocal=TRUE.

When I start my project in the debugger, I see that the assemblies I'd
like to debug aren't getting loaded; instead, the version in the GAC is.

What's going on?
(I'm pretty sure this I used to be able to debug my local dlls.)

Thanks for any help.




Reply With Quote
  #8  
Old   
AT
 
Posts: n/a

Default Re: Why are assemblies loading from the GAC? - 06-21-2006 , 10:06 PM



Hi Schemer,

Thanks for your feedback!

Yes, .Net assembly Strong Name signature is consisted of : its simple text
name, version number, and culture information (if provided) ---- plus a
public key and a digital signature. Once these parts remain the same, 2
assemblies are the same. So your local copy of assembly is the same as the
one you deployed to the GAC. Because of the CLR assembly locating
algorithm, CLR rumtime will always prefer to load GAC copy of your
assembly. Actually, in this scenario, I think it does not matter if CLR is
using the local copy or the GAC copy of assembly, because they are the
same. :-)

Once you changed the version in your local copy of assembly, its Strong
Name signature is changed, so the signature verfication algorithm believes
that your assembly is not the same as the one in the GAC. Since your
project is referring the local copy assembly in the "Add Reference" dialog,
at rumtime, CLR does not believe the one in GAC is what you are referring,
it will use the one in your private bin folder. That's why changing the
version number will prohibit the CLR from loading GAC version of assembly.
Hope this information helps you.

In this scenario, I recommend you not sign the assembly first, and use the
non-Strong Named assembly for debugging purpose. After fully testing, you
may deploy it to the GAC with signing the assembly. I think this way is
more convinient than changing the version number of your local copy
assembly, since after testing the local copy, you still have to deploy it
to GAC again.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.