How to open an assembly in C#
Last Update: Jun 7, 2024

AI changed software development. This is how the pros use it.
Written for working developers, Coding with AI goes beyond hype to show how AI fits into real production workflows. Learn how to integrate AI into Python projects, avoid hallucinations, refactor safely, generate tests and docs, and reclaim hours of development time—using techniques tested in real-world projects.
An assembly is a (compiled) code library used in .NET applications. An assembly contains one or more types and resources. It’s usually in the form of a .DLL file.
There are several ways to open an assembly in C#:
1. Using the Assembly.Load method:
Assembly assembly = Assembly.Load("YourAssemblyName");
This method loads an assembly with the specified name. The assembly name can be a short name, such as “MyAssembly”, or a fully qualified name, such as “MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8675309abcdefg”.
2. Using the Assembly.LoadFrom method:
Assembly assembly = Assembly.LoadFrom("path\\to\\yourassembly.dll");
This method loads an assembly from the specified file path.
3. Using the Assembly.LoadFile method:
Assembly assembly = Assembly.LoadFile("path\\to\\yourassembly.dll");
This method loads an assembly from the specified file path, and it has the same behavior as Assembly.LoadFrom, except that it does not load dependencies from the global assembly cache.
Using the GetTypes to Access Your Types
Once you have loaded an assembly, you can use the GetTypes method to get a list of all the types contained in the assembly, and the CreateInstance method to create an instance of a specific type.
For example:
Type[] types = assembly.GetTypes();
foreach (Type ourType in types)
{
Console.WriteLine(ourType.Name);
}
object obj = assembly.CreateInstance("TypeName");
And that’s all there is to it!
Questions, comments? Let me know!
Can you beat my SkillIQ Score in C#??

I think you can! Take the C# test here to see where you stand!

Skip the hype. The newsletter that keeps you in the know.
AI news curated for engineers. The AI New Hotness Newsletter is what you need.
Zero fluff. Just the research, tools, and infra updates that actually affect your production stack.
Stay up to date on AI for developers - Subscribe on LinkedIn





