重新编译 VB.NET 应用程序以面向 .NET Framework 4.5.2 时出现命名空间限定问题

症状

重新编译 VB.NET 应用程序以面向 Microsoft .NET Framework 4.5.2 时,编译过程中可能会收到以下错误消息:

注意

“{Name}”不是“Windows”的成员。

在此消息中,“{Name}”占位符是 System.Windows 命名空间的子级,例如“Forms”或“Markup”。

例如,错误消息可能如下所示:

注意

“Forms”不是“Windows”的成员。

      

解决方法

此问题涉及.NET Framework 4.5.2“Windows”命名空间的冲突。 它将出现在使用 Windows 的代码中。{Name} 表示 System.Windows。{Name}。

若要解决此问题,请更改代码以完全限定命名空间,或导入完整的命名空间并按其简单名称引用其类型。

例如,以下代码将导致错误:

Module Module1

  Sub Main()

    Windows.Forms.MessageBox.Show("Example")

  End Sub

End Module 

但是,以下代码将成功编译:

Imports System.Windows.Forms

Module Module1

  Sub Main()

    MessageBox.Show("Example")

  End Sub

End Module

以下代码也将成功编译:

Module Module1

  Sub Main()

    System.Windows.Forms.MessageBox.Show("Example")

  End Sub

End Module