views:

34

answers:

1

Each time I open an assembly in reflector, I see this special <Module> type that shows up. Recently, I came across an assembly that has a static method defined in this type and I want to invoke it through reflection. Is this possible?

Btw, this method has privatescope hidebysig method attributes

EDIT:

Assembly assembly = Assembly.LoadFile(assemblyPath);
Type moduleType = assembly.GetType("<Module>");

The above piece of code returns a null.

+1  A: 

I don't have time to experiment to find the right form of name to use, but if you use Assembly.GetTypes() to get all of the types in the assembly, you may be able to find it that way. Bear in mind that an assembly can have many modules. Use Assembly.GetModules() to find all of them.

Jon Skeet
That was the inspiration I needed. Thank you! The method I was looking for was a global method (about which I have never heard before) and was not part of any type. But for some reason, reflector decided to show it under the type '<module>'. I was able to fetch the method using assembly.GetModules()[0].GetMethods(BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static)Btw, the <Module> type doesn't show up when I use Assembly.GetTypes() or when I use ILDasm.
LightX