How to fix 'NonComVisibleBaseClass was detected'
By FoxLearn Published on Feb 15, 2024 612
This can cause issues if you're trying to expose your class to COM, but the base class is not decorated with the appropriate COM visibility attributes.
Mark the Base Class as COM Visible
If you have control over the base class, you can mark it as COM-visible. Add the [ComVisible(true)]
attribute to the base class.
[ComVisible(true)] public class BaseClass { // Your base class code }
Mark the Derived Class as COM Visible
Even if the base class is not COM visible, you can still make the derived class COM-visible. Make sure the class you're trying to expose to COM is marked with the [ComVisible(true)]
attribute.
[ComVisible(true)] public class MyClass : BaseClass { // Your class code }
If you don’t have access to the base class, you can still make your derived class COM-visible.
Go to your project's properties and enable COM interop:
- In Visual Studio, go to Debug > Windows > Exception Settings.
- In the Exception Settings window, expand the Managed Debugging Assistants section.
- Find and uncheck NonComVisibleBaseClass.
For older versions of Visual Studio:
- Navigate to Debug > Exceptions.
- Expand the Managed Debugging Assistants section.
- Uncheck the NonComVisibleBaseClass option.
- Click OK to save your changes.
- How to Share a file between multiple projects in Visual Studio
- How to add .gitignore in Visual Studio
- How to set multiple startup projects in Visual Studio
- How to Auto Increment Version Number in Visual Studio
- How to Add a Custom Prerequisites to Visual Studio Setup Project
- The referenced component could not be found
- How to Auto increment version in Visual Studio
- Starting the Visual Studio Debugger When Attach to Process Doesn’t Work