473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ReferencedAssemblies and the gac

I'm dynamically compiling some code and adding needed referenced assemblies.
When I add references to DLLs using an absolute path there is no problem.
When I add *relative* references to the system DLLs there is, again, no
problem. But when I try to add a *relative* reference to 3rd party managed
DLLs that are present in the GAC I always get a:

Metadata file "xxx" could not be found

error. For example (assuming some third party "BarUtils" assemblies in the
GAC):

StringCollection refs = new StringCollection();
refs.Add("c:\dev\Foo\bin\debug\Foo.dll"); // This will work
refs.Add("System.Security.dll"); // This will work
refs.Add("BarUtils.Forms.Bar.dll"); // This will fail

What am I missing??

Thanks,
-- TB
May 31 '06 #1
4 9687
>What am I missing??

The compilers don't look in the GAC to find referenced assemblies. The
GAC is only used to resolve dependencies at runtime.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 1 '06 #2
Then why does the addition of a relative "System.Security.dll" work
correctly? Are the framework assemblies special-cased in the compiler?

That aside, though, perhaps you can point me to the objects/APIs that I
would need to resolve such an unqualified name to an exact location using the
GAC.

Thanks
-- TB

"Mattias Sjögren" wrote:
What am I missing??


The compilers don't look in the GAC to find referenced assemblies. The
GAC is only used to resolve dependencies at runtime.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jun 1 '06 #3
Thomas,
Then why does the addition of a relative "System.Security.dll" work
correctly? Are the framework assemblies special-cased in the compiler?


Yes, the compiler automatically checks the framework directory. See
the docs for the /lib compiler option for more details.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 1 '06 #4
"Mattias Sjögren" wrote:
Thomas,
Then why does the addition of a relative "System.Security.dll" work
correctly? Are the framework assemblies special-cased in the compiler?


Yes, the compiler automatically checks the framework directory. See
the docs for the /lib compiler option for more details.


Ah, yes, that would explain it!!

Anyway, as usually is the case, posting the question tends to stimulate my
thoughts enough to stumble on another solution. Here is what I'm currently
doing; this routine is used to convert a partial name reference to an
absolute location:

public static string FullReference(string relativeReference)
{
// First, get the path for this executing assembly.
Assembly a = Assembly.GetExecutingAssembly();
string path = Path.GetDirectoryName(a.Location);

// if the file exists in this Path - prepend the path
string fullReference = Path.Combine(path, relativeReference);
if (File.Exists(fullReference))
return fullReference;
else
{
// Strip off any trailing ".dll" if present.
if
(string.Compare(relativeReference.Substring(relati veReference.Length - 4),
".dll", true) == 0)
fullReference = relativeReference.Substring(0,
relativeReference.Length - 4);
else
fullReference = relativeReference;

// See if the required assembly is already present in our current
AppDomain
foreach (Assembly currAssembly in
AppDomain.CurrentDomain.GetAssemblies())
{
if (string.Compare(currAssembly.GetName().Name, fullReference,
true) == 0)
{
// Found it, return the location as the full reference.
return currAssembly.Location;
}
}

// The assembly isn't present in our current application, so attempt
to
// load it from the GAC, using the partial name.
try
{
Assembly tempAssembly =
Assembly.LoadWithPartialName(fullReference);
return tempAssembly.Location;
}
catch
{
// If we cannot load or otherwise access the assembly from the
GAC then just
// return the relative reference and hope for the best.
return relativeReference;
}
}
}

Jun 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mountain Bikn' Guy | last post by:
This code (adapted from the examples in the docs) doesn't make complete sense to me. I have it working, but I'm wondering why I need to declare an assembly reference in 2 places. TIA. Dave ...
1
by: phancey | last post by:
Hi, I am using a library for calling a web service dynamically (library downloaded from http://www.thinktecture.com/Resources/Software/DynWsLib/default.html). This works fine if I use it...
3
by: Grayson | last post by:
I have a need for an "Eval" function and found the perfect sample The problem is it doesn't like "IsDate" being fed into it. Any Ideas? seems like a missing reference, but I can't figure it out......
0
by: phancey | last post by:
whoops - I should have posted this to CSharp not ASPNET: Hi, I am using a 3rd party product to create dynamic web service proxies (downloaded from www.thinktecture.com). My problem is that...
4
by: Jon Rista | last post by:
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm...
1
by: Matt Gertz | last post by:
Phil, Thanks for the notification on this. I'm going to do some investigation on this today & try debugging through the problem, and I'll get back to you either this afternoon or tomorrow...
11
by: Jan | last post by:
I'm using the CSharpCodeProvider to buils some assemblies @ runtime which are never saved as files (cp.GenerateInMemory = true;). The generated assemblies are hierachically dependent on each other...
2
by: Luis Arvayo | last post by:
I am compiling and executing c# code at runtime and I need to define in CompilerParameters.ReferencedAssemblies one of my own assemblies together with the standard System.dll u others. Example:...
1
by: Hannodb | last post by:
Believe it or not, but according to Google, I'm the first person in the world to have this problem. I'm investigating the posibility of using dynamic C# in out application. I've looked at a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.