Question

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.

Was it helpful?

Solution

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;
}

OTHER TIPS

Something like this?

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

bool comVisible = asm.GetCustomAttributes()
                     .OfType<ComVisibleAttribute>()
                     .First()
                     .Value;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top