Loading Dll assemblies at runtime

  • Thread starter Thread starter JH
  • Start date Start date
J

JH

Is it possible to load an assembly at runtime using reflection where the dll
does not have a strong name and is not in the GAC?

If not, is it possible to put an assembly into the GAC without a strong
name?

I'm using the code below (which fails on the load as it needs an assembly
name not a full path)

// Get list of dll's in a specific path
FileInfo[] dllList = GetAssemblyNames(szAssemblyPath);
foreach (FileInfo fi in dllList)
{
Assembly asm = Assembly.Load(fi.FullName);
 
Look at Assembly.LoadFrom which takes the path to the assembly (its CODEBASE)

or Assembly.Load which takes the assembly name and will run the assembly resolution algorithm to find the assembly.

If the target assembly has no strong name Assembly.Load will only look under the application directory (the APPBASE)and sub directories

You cannot put an assembly without a strong name in the GAC as without a strong name there is no way the assembly loader can distinguish between two assemblies with the same name from different authors, and we're back to DLL Hell

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

Is it possible to load an assembly at runtime using reflection where the dll
does not have a strong name and is not in the GAC?

If not, is it possible to put an assembly into the GAC without a strong
name?

I'm using the code below (which fails on the load as it needs an assembly
name not a full path)

// Get list of dll's in a specific path
FileInfo[] dllList = GetAssemblyNames(szAssemblyPath);
foreach (FileInfo fi in dllList)
{
Assembly asm = Assembly.Load(fi.FullName);
 
JH said:
Is it possible to load an assembly at runtime using reflection where the dll
does not have a strong name and is not in the GAC?
Yes.

If not, is it possible to put an assembly into the GAC without a strong
name?

I'm using the code below (which fails on the load as it needs an assembly
name not a full path)

Look at Assembly.LoadFrom and Assembly.LoadFile.
 
Richard Blewett said:
Look at Assembly.LoadFrom which takes the path to the assembly (its CODEBASE)

or Assembly.Load which takes the assembly name and will run the assembly
resolution algorithm to find the assembly.
If the target assembly has no strong name Assembly.Load will only look
under the application directory (the APPBASE)and sub directories
You cannot put an assembly without a strong name in the GAC as without a
strong name there is no way the assembly loader can distinguish between two
assemblies with the same name from different authors, and we're back to DLL
Hell
Cheers guys, I've used Assembly.LoadFrom() and it works fine. Starting to
see that "DLL Hell" phrase popup everywhere recently!
 
Back
Top