2

When I try to create a VB.NET object via interop in VB6, I have noticed I get this error if my VB.NET class doesn't have a constructor:

Error 430 - Class doesn't support automation

All I have to do is put an empty constructor in the VB.NET class, eg:

Public Sub New()

End Sub

and the error is avoided. Is this the expected behaviour?

1
  • Yes. Com classes being wrapped in C# must have a parameterless constructor. This restriction travels both ways. Commented Nov 15, 2012 at 14:02

1 Answer 1

2

VB6 creates objects through COM, using the class factory for a COM coclass. The underlying method is IClassFactory::CreateInstance(). This method does not permit passing any arguments to the factory. It therefore follows that the [ComVisible] .NET class must have a constructor that doesn't take any arguments.

.NET already creates a default constructor for a class, unless you specify a constructor yourself that takes arguments. Which will never be used, you might as well remove it. Now you also don't need the empty default constructor anymore.

Sign up to request clarification or add additional context in comments.

1 Comment

I have found that I get the above error if I have no constructor. The only way it seems to work is if a parameterless constructor is put in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.