【问题标题】:code compiles on visual studio 2015 but failing on 2013代码在 Visual Studio 2015 上编译,但在 2013 年失败
【发布时间】:2016-07-13 15:22:43
【问题描述】:

我在课堂上有这个方法

public static DataTable ConvertCellSetToDataTable(CellSet cellSet)
{
    return new DataTable();
}

我的 packages.config 中有 Microsoft.AnalysisServices.AdomdClient 作为 nuget 包,我没有 System.Xml 作为项目参考。

  <package id="Microsoft.AnalysisServices.AdomdClient" version="12.0.2000.8" targetFramework="net452" />

此项目无法使用 Visual Studio 2013 Pro 编译,但同一解决方案文件在同一台机器上的 Visual Stuido 2015 Pro 中兼容。

来自 VS2013 的错误信息如下:

error CS0012: The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

我可以接受这个失败,但为什么它可以使用 Visual Studio 2015 编译?这里有什么新东西?

这里有我所有的文件:

https://gist.github.com/atwayne/ad8fdc06ee831626361609cfb5935638

【问题讨论】:

  • 罗斯林是新来的。 C# 编译器,大约在 4.5 版左右,对想要知道 间接 引用的类型有更严格的要求。某种方法重载问题,C#语言规范没有提到的细节。
  • 你试过using System.Xml;吗?
  • 这就是我的意思。 old 版本 (4.5) 变得更加严格。
  • @Stan no 我的课堂上没有 using 语句,添加它不会修复错误
  • 所以您尝试添加using System.Xml.Serialization,而不仅仅是using System.Xml,但没有奏效?

标签: c# visual-studio-2013 visual-studio-2015 system.xml


【解决方案1】:

已经有一段时间了,我引用@Hans Passant 的评论作为答案:

罗斯林是新来的。 C# 编译器,大约在 4.5 版左右,有一个 对想知道间接的类型更加严格 参考。某种方法重载问题,一个细节 C#语言规范没有提及。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 2011-04-12
    • 2018-12-20
    • 1970-01-01
    • 2013-12-30
    相关资源
    最近更新 更多