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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Sep 3, 2008, 2:58 AM EDT
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);
}
}
}
}
}
}
}
Peter16 reputationPosted Nov 4, 2008, 12:23 AM EST
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
AlanRank #669 · 3.6K reputationPosted Nov 4, 2008, 10:46 AM EST
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.