Hi. I have a c# assembly called test.dll, it has some entrypoints marked by[CustomAction]. How do i search the file and find the various entrypoints?
Example:
[CustomAction]
private void CA1()
{
}
How do I get CA1 returned?
Hi. I have a c# assembly called test.dll, it has some entrypoints marked by[CustomAction]. How do i search the file and find the various entrypoints?
Example:
[CustomAction]
private void CA1()
{
}
How do I get CA1 returned?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Sep 3, 2008, 6:58 AM
Reflection is your friend:
using System;
using System.Reflection;
class Program
{
static void Main()
{
Assembly asm = Assembly.LoadFrom("test.dll");
Type[] types = asm.GetTypes();
BindingFlags bf = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
Console.WriteLine("The following methods are decorated with CustomAction: \n");
foreach(Type t in types)
{
MethodInfo[] mia = t.GetMethods(bf);
foreach(MethodInfo mi in mia)
{
object[] attribs = mi.GetCustomAttributes(false);
if (attribs.Length > 0)
{
foreach(object attrib in attribs)
{
if (attrib.ToString() == "CustomActionAttribute")
{
Console.WriteLine("{0}.{1}", t, mi.Name);
}
}
}
}
}
}
}
AlanPosted Nov 4, 2008, 3:46 PM
TBH, Peter, I don't understand why that doesn't work but when I googled to see whether the problem had been reported before I came up with this:
http://www.csharphelp.com/board2/read.html?f=1&i=52158&t=52158
So, this suggests that if you map a drive letter to the network drive, it will work OK.
PeterPosted Nov 4, 2008, 5:23 AM
I tried this and it worked perfectly.
Except now I moved the dll on to a network drive, and now
object[] attribs = mi.GetCustomAttributes(false);
does not work as it used to. attribs is not filled with [0] = {Microsoft.Deployment.WindowsInstaller.CustomActionAttribute} like it is when the dll is on a local drive...
I have no clue why...
Any suggestions?
Best regards
Peter