473,788 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 AssemblyIsLoade d(string pathToAssembly)
{
foreach (Assembly currentAssembly in
AppDomain.Curre ntDomain.GetAss emblies())
{
try // This try/catch block is necessary because the .Location
property is not supported in a dynamic assembly.
{
if (currentAssembl y.Location.Equa ls(pathToAssemb ly,
StringCompariso n.OrdinalIgnore Case))
{
return true;
}
}
catch (Exception ex) { }
}

return false;
}
Thanks in advance.

Jun 27 '08 #1
1 6051
You could always use the Load(AssemblyNa me) 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 AssemblyIsLoade d(string pathToAssembly)
{
foreach (Assembly currentAssembly in
AppDomain.Curre ntDomain.GetAss emblies())
{
try // This try/catch block is necessary because the .Location
property is not supported in a dynamic assembly.
{
if (currentAssembl y.Location.Equa ls(pathToAssemb ly,
StringCompariso n.OrdinalIgnore Case))
{
return true;
}
}
catch (Exception ex) { }
}

return false;
}
Thanks in advance.

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2339
by: Daylor | last post by:
can shadowcopy be done with private assembly ? any info about how shadowcopy actually works ? when im compiling an assembly (while the assembly file is in use ), what i need to do ? change vertion ? change name of file ? how the appDomain will know to load the new assembly ?
11
3441
by: Z D | last post by:
Hello, If I have a .NET assembly, how do I determine what version of the .NET framework it.... 1) was compiled against 2) is supposed to use 3) is compatible with? Is there a utility that will extract this info somehow?
1
5022
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web Service dynamically loads up an assembly that implements an Interface I called IDatabase. To load the assembly and create an object, I wrote this function: private IDatabase LoadDatabasePlugin( string assemblyFile, string
1
5947
by: James Wansley | last post by:
I am currently running a c# service that dynamically loads assemblies using System.Reflection.Assembly.LoadFrom("aDll.dll"). These assemblies are stored in an arraylist after they are loaded. I would like to periodically report the memory usage of each assembly within the arraylist. I tried System.Diagnostics.ProcessModule.ModuleMemorySize, but this only shows the size of the structures within the .dll, not the current memory usage. ...
1
2794
by: Zachary Hartnett | last post by:
I was trying to write a routine this morning that would open a given assembly, walk the inheritance tree of classes in the assembly, and provide a list of classes in the assembly that inherit from DataSet. Here is a snippet from the routine I came up with: ------------------------------------------------------------ openFileDialog.ShowDialog(); Assembly assembly = Assembly.LoadFile(openFileDialog.FileName);
2
1647
by: Jan | last post by:
Regarding my post "CSharpCodeProvider: referencing other generated "InMemory" assembly" 4/27/2006 and the blog from Greg Young http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx I have now implemented a fine system with code semilar to Greg's example code. I have a warning/comment/question: When the generated main assembly is called for the first time (in my application a static initialize function) another instance of...
4
19532
by: Object01 | last post by:
We're working with some benchmarks designed to test x86 vs. x64 performance (both on a x64 system). To ensure that our assemblies are loaded as x86 or x64, we specifically target our builds to the appropriate platform, avoiding using the "Any CPU" setting. (It's my understanding that on an x64 system, the runtime will JIT an "Any CPU" assembly as x64 if it's able.) All this raised an interesting question: given an arbitrary .NET...
12
6622
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I am writing a web app to be widely distributed where I do not know the installed .NET Framework version. I want to take advantage of some .NET 3.0 classes if they are installed, but gracefully degrade if not available. (Specifically, I want to use System.Windows.Media.Imaging.BitmapMetadata to extract metadata from JPEG files when 3.0 is available, but will resort to System.Drawing.Image if .NET 3.0 is not installed.) What is the...
7
7623
by: Cramer | last post by:
I'm wondering if there is an easy way to programmatically determine if an assembly is installed in the GAC. This would be similar to our ability to easily determine if a file exists (File.Exists(path)) - but for an assembly, of a particular version, etc in the GAC. I have googled this and failed to find anything useful. Thanks
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.