Reputation: 4695
I am preloading an assembly in the Application_Start() using Assembly.LoadFrom("pathtomyassembly").
Why am I not able to get my assembly using Assembly.Load("MyAssemblyName") just like I can with any other assembly loaded automatically from the bin directory.
Is there a way to do this without calling LoadFrom() with the assembly path every time?
UPDATE:
The weird thing is, when I use
AppDomain.CurrentDomain.GetAssemblies()
I can see that my assembly is loaded in the AppDomain.
Is there a way to get it without looping through the assemblies?
Upvotes: 0
Views: 237
Reputation: 10623
you need to supply fully qualified name Assembly.Load [Assembly].Load("Assembly text name, Version, Culture, PublicKeyToken")
.
E.g.
Assembly.Load("ActivityLibrary, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null");
Ref:
http://geekswithblogs.net/rupreet/archive/2010/02/16/137988.aspx
http://msdn.microsoft.com/en-us/library/x4cw969y.aspx
Upvotes: 1
Reputation: 4695
I ended up looping through AppDomain.CurrentDomain.GetAssemblies() to get my assembly.
public static Assembly GetAssemblyFromAppDomain(string assemblyName)
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (assembly.FullName.StartsWith(assemblyName + ","))
{
return assembly;
}
}
return null;
}
Everything seems to work fine.
Upvotes: 0
Reputation: 1260
My hunch is you can't use Assembly.Load("MyAssemblyName")
because there's no matching DLL in your program's bin directory. Your build script would need to manually copy that DLL from pathtomyassembly
to your program's bin directory, or you'd need to add it as a link in your solution and make sure "Copy to Output Directory" is checked.
Upvotes: 0