为什么VS 2005不断给我“'x'在命名空间'y'”错误中不明确?

问题描述:

赏金:我会送通过PayPal $ 5,修复这个问题,我的答案。为什么VS 2005不断给我“'x'在命名空间'y'”错误中不明确?

我不知道VS设置我改变什么,或者如果它是一个web.config设置或什么,但我一直在错误列表中得到这个错误,但所有的解决方案构建的罚款。下面是一些例子:

 
Error 5 'CompilerGlobalScopeAttribute' is ambiguous in the namespace 'System.Runtime.CompilerServices'. C:\projects\MyProject\Web\Controls\EmailStory.ascx 609 184 C:\...\Web\ 
Error 6 'ArrayList' is ambiguous in the namespace 'System.Collections'. C:\projects\MyProject\Web\Controls\EmailStory.ascx.vb 13 28 C:\...\Web\ 
Error 7 'Exception' is ambiguous in the namespace 'System'. C:\projects\MyProject\Web\Controls\EmailStory.ascx.vb 37 21 C:\...\Web\ 
Error 8 'EventArgs' is ambiguous in the namespace 'System'. C:\projects\MyProject\Web\Controls\EmailStory.ascx.vb 47 64 C:\...\Web\ 
Error 9 'EventArgs' is ambiguous in the namespace 'System'. C:\projects\MyProject\Web\Controls\EmailStory.ascx.vb 140 72 C:\...\Web\ 
Error 10 'Array' is ambiguous in the namespace 'System'. C:\projects\MyProject\Web\Controls\EmailStory.ascx.vb 147 35 C:\...\Web\ 

    [...etc...] 

Error 90 'DateTime' is ambiguous in the namespace 'System'. C:\projects\MyProject\Web\App_Code\XsltHelperFunctions.vb 13 8 C:\...\Web\ 

你可以想像,这真是烦人,因为有蓝色的波浪强调无处不在的代码,并在错误列表窗格中筛选出相关的错误几乎是不可能的。我已经检查了默认的ASP.Net web.config和machine.config,但是没有任何东西显示出来。


编辑:这里的一些源在错误发生:

'Error #5: whole line is blue underlined' 
<%= addEmailToList.ToolTip %> 

'Error #6: ArrayList is blue underlined' 
Private _emails As New ArrayList() 

'Error #7: Exception is blue underlined' 
Catch ex As Exception 

'Error #8: System.EventArgs is blue underlined' 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

'Error #9: System.EventArgs is blue underlined' 
Protected Sub sendMessage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sendMessage.Click 

'Error #10: Array is blue underlined' 
Me.emailSentTo.Text = Array.Join(";", mailToAddresses) 

'Error #90: DateTime is blue underlined' 
If DateTime.TryParse(data, dateValue) Then 

编辑:GACUTIL结果

 
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil -l mscorlib 

Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4318.0 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 

The Global Assembly Cache contains the following assemblies: 

The cache of ngen files contains the following entries: 
     mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c5619 
34e089, Custom=5a00410050002d004e0035002e0031002d003800460053002d003700430039004 
40037004500430036000000 
     mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c5619 
34e089, Custom=5a00410050002d004e0035002e0031002d0038004600440053002d00370043003 
900450036003100370035000000 

Number of items = 2 
 
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil" -l mscorlib 

Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0.50727.42 
Copyright (c) Microsoft Corporation. All rights reserved. 

The Global Assembly Cache contains the following assemblies: 

Number of items = 0 

编辑:从NGEN有趣的结果:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ngen display mscorlib /verbose 

Microsoft (R) CLR Native Image Generator - Version 2.0.50727.832 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 

NGEN Roots: 

mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=5a00410050002d004e0035002e0031002d003800460053002d00330037004200430043003300430035000000 
    ScenarioDefault 
     mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=5a00410050002d004e0035002e0031002d003800460053002d00330037004200430043003300430035000000 
      DisplayName = mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
      Native image = {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
      Hard Dependencies: 
      Soft Dependencies: 
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    ScenarioNoDependencies 
     mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
      DisplayName = mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
      Native image = {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
      Hard Dependencies: 
      Soft Dependencies: 

NGEN Roots that depend on "mscorlib": 
[...a bunch of stuff...] 

Native Images: 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
    Source MVID: {D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
    Source HASH: bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 
    NGen GUID sign: {7681CE0F-F0E7-F03A-2B56-96345589D82B} 
    OS:  WinNT 
    Processor: x86(Pentium 4) (features: 00008001) 
    Runtime: 2.0.50727.832 
    mscorwks.dll: TimeStamp=461F2E2A, CheckSum=00566DC9 
    Flags:  
    Scenarios:  <no debug info> <no debugger> <no profiler> <no instrumentation> 
    Granted set: <PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> 

    File:  

C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\0fce8176e7f03af02b5696345589d82b\mscorlib.ni.dll 
    Dependencies: 
     mscorlib, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089: 
      Guid:{D34102CF-2ABF-4004-8B42-2859D8FF27F3} 
      Sign:bbf5cfc19bea4e13889e39eb1fb72479a45ad0ec 

应该只有在本机映像一个mscorlib程序,是否正确?我怎样才能摆脱其他人?

+0

奖励可以去你或你选择的慈善机构。 – travis 2008-09-18 14:04:02

基于你的gacutil输出的结果(感谢你这样做;我认为它有帮助),我会说你需要尝试在.NET Framework安装和Visual Studio 2005上运行修复。我不是当然,如果这能解决它,但正如你可以从gacutil的输出中看到的那样,你没有2.0。

我从VS2005命令提示符下,我得到:

 
Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0.50727.42 
Copyright (c) Microsoft Corporation. All rights reserved. 

The Global Assembly Cache contains the following assemblies: 
    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86 

Number of items = 1 

我从VS2003命令提示符下,我得到:

 
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573 
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. 

The Global Assembly Cache contains the following assemblies: 

The cache of ngen files contains the following entries: 
    mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=5a00410050002d004e0035002e0031002d003800460053002d00330037004200430043003300430035000000 
    mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=5a00410050002d004e0035002e0031002d0038004600440053002d00330037004200440036004600430034000000 

Number of items = 2 

当寻求帮助诊断编译问题,它常常有助于发布违规的源代码:)

这些错误确实意味着,与其他和编译器指定的名称冲突无法解决此。它看起来有点古怪寿..

我已经被这个打为好,特别是System.Data.SqlClient的。请尝试取消在项目经理的命名空间和手动包括他们在.vb文件,就像你使用C#:

进口System.Data.SqlClient的

拿一个错误(如ArrayList),并与更换型全限定名(我不确定,但我想在这里:System.Collection.ArrayList)。如果错误消失,你确实有解决冲突。如果不是,那是别的。
如果所有的解决方案,打造“精”这些错误,我建议您清洗项目。删除所有编译的东西(dll,pdb,无论如何),也影响缓存的东西。也许它编译是因为它使用旧版本的东西。

我知道这听起来很奇怪,但你使用“生成”或“重建”来构建解决方案?如果我有这样的有趣问题,解决方案的“重建全部”将有所帮助。

最近我有同样的错误。 以下是我如何修复它(我希望它也适用于您):

- 打开您的项目属性,转到参考部分。

- 在上面的部分删除对系统的引用。

我认为它引用了系统两次,但它只显示一次。因此,这些模糊的参考。

+0

不幸的是,在参考文献中没有列出任何系统。我想知道在VS中是否有一些全局引用设置,尽管可能有重复的引用... – travis 2008-09-18 14:17:15

+0

列出了哪些引用? GAC中包含以下内容:C:\> gacutil -l mscorlib – 2008-09-18 17:31:57

昨天我在VS2005 ASP.NET网站项目相同:突然,随着任何以前的重大代码更改,在'y'出现的命名空间中加载'x'是模糊的,它们全部来自非常基本的符号,如EventArgs,Type,DBNull等。

即时原因是双引用mscorlib,因为我可以在VS的类视图中看到。我相信真正的原因是自动Windows Update迫使我在几分钟前重启机器。

尝试像建立一个全新的ASP.NET网站项目这样的特技,复制粘贴源文本(在同一台机器上 - 没有帮助)或移动项目在第二台机器上使用相同的VS2005安装(它有帮助,项目正常工作)我几乎可以肯定,我的代码没有问题,但与我的VS/.NET配置。我绝望地不知道如何治愈它,因为除了这个之外,互联网上没有描述类似的麻烦。

重新安装.Net Framework 2.0

这应该解决它。之后,gacutil(从v2.0)将显示1 mscorlib而不是0.