473,378 Members | 1,527 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,378 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 9685
>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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.