1

I'm trying to follow the promising suggestion posted here to try StatePrinter as a shortcut to rolling my own ToString methods. I agree with the OP that it is a shame that VS still can't generate this method for me.

I've got a fairly large project, in VS2015 (Community Edition), with both VB and C# code. I added the current stable version of StatePrinter using NuGet.

I can make the example code from the SO answer work fine in my C# code but when I do what I think is the equivalent in my VB code:

Private Shared sp As StatePrinter.Stateprinter = New StatePrinter.Stateprinter
    Public Overrides Function ToString() As String
        Return sp.PrintObject(Me)
    End Function

I just get the compiler error

'Stateprinter' is ambiguous in the namespace 'StatePrinter' 

There IS another constructor, StatePrinter (note difference in capitalization only) which is deprecated and, in any case, generates the same error message.

I'm led to the unfortunate conclusions that

  1. VB in VS2015 is acting as if it is case insensitive. Can that be true?
  2. No one else is using StatePrinter from VB.

Can anyone provide any suggestions on how to use StatePrinter from VB? I'm willing to believe I'm making some rather brain-dead mistake in converting the C# example to VB.

Community
  • 1
  • 1
Anne Gunn
  • 2,347
  • 1
  • 28
  • 42
  • Try putting brackets around the name. Like `Private Shared sp As New StatePrinter.[Stateprinter]`. – RBarryYoung Jan 29 '16 at 19:34
  • @RBarryYoung, I understand the use of brackets to let me use a reserved word as a variable name. But the ambiguity here is not with a reserved word but rather with another method in the same StatePrinter package. I've already torn down my test environment so I can't try your suggestion easily. Can you provide a reference that leads you to think that this will work in this case? (And, if you can, consider posting as an answer so I have the option of marking yours as the right answer.) – Anne Gunn Jan 29 '16 at 23:48
  • It's just a long shot. In BASIC's heritage (as well as some other, no longer popular languages) the brackets were a way to quote a name against a variety of issues, including a case-sensitive name in an external library. I am not aware of anyone or anything saying that it will work in VB.net, but there have been BASIC's where it *did* work. – RBarryYoung Jan 30 '16 at 20:20
  • @RBarryYoung Ah, now I understand why you suggested it. I've checked the VB.Net docs since yesterday and am fairly certain that it won't work in this case. Oddly, now that I've been forced to pay attention to the case insensitivity issue, I'm seeing lots of little weird behaviors in the VS IDE that it explains and that I had been choosing to ignore. This was one of the more productive total failures I've ever had. – Anne Gunn Jan 31 '16 at 00:16
  • Yes, there is nothing in the docs that say it should work, but there are things written into the compiler that are not in the docs. – RBarryYoung Jan 31 '16 at 19:17

2 Answers2

0

As soon as I got done writing #1 in the question above, I was able to figure out how to search for the answer to that bit.

Yes, VB is case insensitive, at least, as far as it needs to be in this case: See the rather nice writeup here: https://stackoverflow.com/a/2301980/165164

So, we're left with the rather plaintive: is no one else using StatePrinter from VB?

Community
  • 1
  • 1
Anne Gunn
  • 2,347
  • 1
  • 28
  • 42
  • There are a few things like this. the MySql datatypes include a `DateTime` and a `Datetime` in the enumeration – Ňɏssa Pøngjǣrdenlarp Jan 29 '16 at 19:35
  • Clearly this is a silly ambiguity - as well as the already existing `StatePrinter.StatePrinter` (the now obsolete one). Perhaps a bugreport on the project page will solve the issue in the comming version. – Carlo V. Dango Feb 02 '16 at 18:37
0

It is near impossible to use this directly in VB and get around the ambiguous name issue. You could write a class library wrapper in C# that doesn't expose this mismatch (that is, it has an internal StatePrinter object and exposes constructors that are PascalCased the same.

Another option would be to use reflection in the VB project to get around the case insensitivity.

You could also create a GitHub issue. Or, be a contributor to the project and create a suggested fix for it. :)

Martin Soles
  • 534
  • 3
  • 8
  • Since my project already has C# code, that's probably what I'll do the next time I paint myself into a corner and think how nice it would be to see more detail in my log file. I've gotten out of the corner the hard way, today, with patience and the debugger. But thanks for the suggestion. (And I think the fix is obvious and probably just going to happen in due course. When the deprecated StatePrinter constructor is removed, there's every reason the problem will just go away.) – Anne Gunn Jan 29 '16 at 23:40