2

I have a DLL that may or may not have its ComVisible attribute set to true. I'm not sure how it was built, or with what attributes? All I know is that it's a .Net DLL. Simply put, how can I tell if it is Com Visible?

Sorry if this is a duplicate. All of my searches about this return results that show how to make a DLL ComVisible. I know how to do that.

user2023861
  • 8,030
  • 9
  • 57
  • 86

2 Answers2

3

You could check the ComVisibleAttribute of the assembly using reflection:

private static bool IsComVisible(string assemblyPath)
{
  var assembly = Assembly.LoadFile(assemblyPath);

  var attributes = assembly.GetCustomAttributes(typeof(ComVisibleAttribute), false);

  if (attributes.Length > 0)
  {
    return ((ComVisibleAttribute)attributes[0]).Value;
  }

  return false;
}
Gene
  • 4,192
  • 5
  • 32
  • 56
0

Something like this?

Assembly asm = Assembly.GetExecutingAssembly(); //Assembly.LoadFile, Assembly.Load

bool comVisible = asm.GetCustomAttributes()
                     .OfType<ComVisibleAttribute>()
                     .First()
                     .Value;
I4V
  • 34,891
  • 6
  • 67
  • 79