Eduard Lepner
Eduard Lepner

Reputation: 699

Assembly.Load fails even assembly is already loaded in domain

I'm trying to make work the following code (it was decompiled):

foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
    if ((!assembly.FullName.StartsWith("System") && !assembly.FullName.StartsWith("Microsoft")) && !assembly.FullName.StartsWith("mscorlib"))
       {
           list.Add(assembly.FullName);//keep the name of assembly.
       }
}
foreach (string assemblyStirng in list)
{
     var assembly = Assembly.Load(assemblyString);//here FileNotFoundException is thrown.
}

How is it possible? Dll is already in domain and Assembly.Load should return it.

Upvotes: 0

Views: 606

Answers (2)

Adrian Thompson Phillips
Adrian Thompson Phillips

Reputation: 7141

Could it be that Assembly.Load(string) takes an assembly name in it's long form (i.e. strongly named, maybe installed in the GAC), but you're giving it the short assembly name?

Upvotes: 1

Nickolai Nielsen
Nickolai Nielsen

Reputation: 942

Turn on assembly load logging with fusion log view: Fusion Log View

It will tell you detailed information about why i can't find it.

Some reasons could be, that it was loaded from somewhere else than the application dir, or it did find different versions of the same dll

Upvotes: 2

Related Questions