TFS签出后Switch类出现错误

huangapple go评论121阅读模式
英文:

Error with Switch class after TFS checkout

问题

我有一个老旧的VB.NET代码需要调试。它在TFS下(可能是2012版本)。当我将其下载到我的电脑并且什么都不改变时,它可以成功编译。但一旦我检出它,就会出现以下错误:
`BC30109: 'Switch' 是一个类类型,不能用作表达式。`

这是代码

Dim rdr As SqlDataReader = ExecuteReader()
Do While rdr.Read
If Not IsDBNull(rdr("VAR_VALUE")) Then
DefaultSalUnit = Switch(CLng(rdr("VAR_VALUE")) = 12, "Monthly", CLng(rdr("VAR_VALUE")) = 1, "Yearly")
End If
Loop
rdr.Close()

DefaultSalUnit 是一个 *String*。
我尝试导入 `System.Diagnostics`,但它立即消失。将其追加到 `Switch` 仍然生成相同的错误。

为什么会出现这种奇怪的行为?有什么想法吗?
英文:

I have an old VB.NET that I am asked to debug. It is under TFS (perhaps 2012). When I download it to my PC and change nothing it compiles successfully. But as soon as I check it out, I get
BC30109: 'Switch' is a class type and cannot be used as an expression.

This is the code

Dim rdr As SqlDataReader = ExecuteReader()
Do While rdr.Read
   If Not IsDBNull(rdr("VAR_VALUE")) Then
       DefaultSalUnit = Switch(CLng(rdr("VAR_VALUE")) = 12, "Monthly", CLng(rdr("VAR_VALUE")) = 1, "Yearly")
   End If
Loop
rdr.Close()

DefaultSalUnit is a String.
I tried imporing System.Diagnostics and it disappears instantly. Appending it to Switch still generates the same error.

Why is this weird behavior? Ideas?

答案1

得分: 2

我相信这是命名空间之间的冲突。

你得到的是 System.Diagnostics,你应该寻找 Microsoft.VisualBasic.Interaction。

你可以要么在方法调用前加上前缀,要么在命名空间之间进行调整以强制正确选择。

英文:

I believe it is a clash between namespaces.

You're getting System.Diagnostics and you should be looking for Microsoft.VisualBasic.Interaction.

You can either prefix your method call or juggle with the namespaces to force the correct selection.

huangapple
  • 本文由 发表于 2023年3月9日 14:32:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75681147.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定