Mercury Class Constructor scope difference from VB.NET

I’m back to moving one of my VB.NET solutions to Mercury. One of my projects is a class library that has a Public Class with a constructor that looks like this:

		Sub New(pDataContextType As Type)
		End Sub

Notice that the Sub is not explicitly defined as “Public”. However, in VB.NET this is treated as Public - creating a new object with this constructor compiles fine, apparently because this is the default in VB.NET.

However, after switching the project to Mercury, I’m getting this error:

(E672) Type "xxxx" has no accessible constructors

After experimenting a bit with this, it appears to me that this only happens if the class is in a different project from the calling code. If it is in the same project, it finds the constructor without an issue.

I’ve attached an example. The “ScopeExample.sln” points to the vbproj files, and should compile fine. The “ScopeExampleMercury.sln” has the exact same code files but points to the elements files instead, and shows the compile error.

I’ll admit I shouldn’t rely on the defaults, and so it was no big deal to change it to add the “Public” for the Sub. On the other hand, depending on the code base being moved to Mercury, it might be a lot more work than it was for me - I only had a few places where this was an issue.

–Avonelle (592.7 KB)

For the fixers, here the matrix again:


1 Like

Thanks, logged as bugs://85592

logged to review all default visibilities and make them match.

workaround, for now, would ofc be to mark the .ctor as Public explicitly…

1 Like

Yep, that’s exactly what I’m doing in the meantime. Fortunately for me, this was only in a few spots.



bugs://85592 got closed with status fixed.

1 Like

Almost fixed :wink:

Found another:
When there are partial classes (like forms with a designer file) where 1 part has it’s visibility specified and one has not, the specified visibility should be used for both.

To reproduce: open a new Winforms (.Net classic) template and compile.

Separate error, really. I assume right now it fails on “visibility must match”?

Thanks, logged as bugs://85601 — for the partial classes

Yes, was caused by this fix as the default for the class in the namespace is now Friend (was Public)

1 Like

bugs://85601 got closed with status fixed.