"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;
}
}
}