仅在Windows 10上出现令人费解的c#编译器CS0234错误

仅在Windows 10上出现令人费解的c#编译器CS0234错误,c#,visual-studio,.net-4.0,windows-10,google-shopping-api,C#,Visual Studio,.net 4.0,Windows 10,Google Shopping Api,将一个针对.Net 4.0的Visual Studio 2010解决方案从Windows 7迁移到Windows 10环境时,我遇到了一个CS0234编译错误:找不到类型或命名空间名称“我的命名空间名称”(是否缺少using指令或程序集引用?) 引发此错误的原因似乎是对我的一个库中的第三方库中的类型的引用,其中还定义了“我的命名空间名称”。编译链接到此库中的另一个库时出现错误消息。第三方库是使用NuGet和受支持的.Net 4.0安装的 我用两个类库创建了一个简单的测试解决方案来演示这个问题。为

将一个针对.Net 4.0的Visual Studio 2010解决方案从Windows 7迁移到Windows 10环境时,我遇到了一个CS0234编译错误:找不到类型或命名空间名称“我的命名空间名称”(是否缺少using指令或程序集引用?

引发此错误的原因似乎是对我的一个库中的第三方库中的类型的引用,其中还定义了“我的命名空间名称”。编译链接到此库中的另一个库时出现错误消息。第三方库是使用NuGet和受支持的.Net 4.0安装的

我用两个类库创建了一个简单的测试解决方案来演示这个问题。为第一个库安装了第三方库。我从第一个库中的第三方库声明了一个类型为ShoppingContentService的变量:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.Apis.ShoppingContent.v2;
using Google.Apis.ShoppingContent.v2.Data;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Requests;
using log4net;

namespace ClassLibrary1
{
    public class Class1
    {
        //comment out the following declaration the compilation error goes away
        private static ShoppingContentService s_service;

        public static void Method1()
        {
            System.Console.WriteLine("hello");
        }
    }
}
第二个库引用第一个库。当使用ClassLibrary1编译指向的解决方案时,该错误再次出现语句:

错误2找不到类型或命名空间名称“ClassLibrary1” (是否缺少using指令或程序集 参考?)c:\Visual Studio 2010\Projects\ClassLibrary1\ClassLibrary2\Class2.cs 5 7 ClassLibrary2

解决方案文件可从以下位置下载:

切换到VS 2017并不能解决问题,将目标框架更改为.Net 4.5也不能解决问题


提前感谢您关注这个问题,我们将非常感谢您提供的任何信息

看看你收到的另一个警告,它会提示你出了什么问题

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?) ClassLibrary2 D:\Users\Tami\Downloads\Test\ClassLibrary2\Class2.cs 5 Active Warning CS0169 The field 'Class1.s_service' is never used ClassLibrary1 D:\Users\Tami\Downloads\Test\ClassLibrary1\Class1.cs 17 Active Warning All projects referencing ClassLibrary1.csproj must install nuget package Microsoft.Bcl.Build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317569. ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2 现在,您将能够引用
ClassLibrary1
而不会出现警告或错误(除了
字段“Class1.s_service”从未使用过
one)


附言

切换到VS 2017并不能解决问题,将目标框架更改为.Net 4.5也不能解决问题


实际上,如果您在升级到.NET 4.5后删除了Microsoft.Bcl.Async包及其所有依赖项(就像您应该删除的那样),它也会解决您的问题。

我认为错误消息是“您是否缺少[…]程序集引用?”…@elgonzo没有,他有引用,他所缺少的是看那些同样显示的警告。谢谢你的建议,斯科特!在我们的解决方案中,警告也出现在Windows 7上,但编译完成时没有出现问题,因此我没有想到它们与错误有关。在将库添加到packages.config文件后,编译问题在示例中消失了,但在原始解决方案中没有,因为原始解决方案只看到警告消失。Win 10机器首先有VS 2017,现在有VS 2017和2010,并且有一个v4.X.NetFramework目录。我将尝试通过对样本进行更改,看看是否可以重新解决该问题。 Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?) ClassLibrary2 D:\Users\Tami\Downloads\Test\ClassLibrary2\Class2.cs 5 Active Warning CS0169 The field 'Class1.s_service' is never used ClassLibrary1 D:\Users\Tami\Downloads\Test\ClassLibrary1\Class1.cs 17 Active Warning All projects referencing ClassLibrary1.csproj must install nuget package Microsoft.Bcl.Build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317569. ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2 Warning The primary reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "D:\Users\Tami\Downloads\Test\ClassLibrary1\bin\Debug\ClassLibrary1.dll" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". ClassLibrary2
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" />
  <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
  <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
  <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net40" />
</packages>