修复LINQPad

问题描述

如果我是

  1. 在LINQPad 6中创建一个新的C#查询
  2. 添加System.ServiceModel.Http NuGet软件包或another package that references it
  3. 尝试从System.ServiceModel命名空间实例化一个类,例如System.ServiceModel.BasicHttpBinding

通往以下.linq文件

<Query Kind="Expression">
  <NuGetReference>System.ServiceModel.Http</NuGetReference>
</Query>

new System.ServiceModel.BasicHttpBinding()

然后我得到一个编译错误CS0433 The type 'BasicHttpBinding' exists in both 'System.Private.ServiceModel,Version=4.7.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' and 'System.ServiceModel.Http,PublicKeyToken=b03f5f7f11d50a3a'

如果我在Visual Studio中创建一个项目并添加相同的NuGet包和代码,则不会出现此错误

根据the C# Language reference for the error,应该可以通过使用-reference编译器选项或不引用其中一个程序集来进行解析。但是,我似乎找不到在LINQPad中使用此编译器选项的方法,也找不到任何方法删除System.Private.ServiceModel的程序集引用。

如何解决错误

解决方法

这是LINQPad中的一个错误,由一个晦涩的场景触发。 System.Private.ServiceModel程序包包含一个lib文件夹,其中包含在运行时需要的程序集;以及一个ref文件夹,其中包含underscore.underscore文件,该文件指示编译器不应引用任何程序集。由于LINQPad找不到参考程序集,因此它会将lib文件夹中的程序集提供给编译器,这会导致错误。

我已经准备好修复程序,并且正在运行回归测试。该修复程序可能会将其纳入6.11.2 beta版本,该版本应在一两天内发布。