471,348 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Determine if Assembly Is Loaded

Is there an easier way to determine if a specific assembly is loaded into
the current AppDomain?

I'm thinking that there has to be a way to do it without looping through all
currently loaded assemblies, yet I couldn't find how to do it without
looping.

This is what I have:

private bool AssemblyIsLoaded(string pathToAssembly)
{
foreach (Assembly currentAssembly in
AppDomain.CurrentDomain.GetAssemblies())
{
try // This try/catch block is necessary because the .Location
property is not supported in a dynamic assembly.
{
if (currentAssembly.Location.Equals(pathToAssembly,
StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch (Exception ex) { }
}

return false;
}
Thanks in advance.

Jun 27 '08 #1
1 5504
You could always use the Load(AssemblyName) method, which would ensure that
the assembly is loaded. You cannot load an assembly into an appDomain more
than once.
-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"Verde" wrote:
Is there an easier way to determine if a specific assembly is loaded into
the current AppDomain?

I'm thinking that there has to be a way to do it without looping through all
currently loaded assemblies, yet I couldn't find how to do it without
looping.

This is what I have:

private bool AssemblyIsLoaded(string pathToAssembly)
{
foreach (Assembly currentAssembly in
AppDomain.CurrentDomain.GetAssemblies())
{
try // This try/catch block is necessary because the .Location
property is not supported in a dynamic assembly.
{
if (currentAssembly.Location.Equals(pathToAssembly,
StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
catch (Exception ex) { }
}

return false;
}
Thanks in advance.

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James Wansley | last post: by
1 post views Thread by Zachary Hartnett | last post: by
12 posts views Thread by =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post: by
1 post views Thread by Ronak mishra | last post: by

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.