选取两个版本的 System.Linq 导致的不明确调用

发布于 2025-01-05 17:30:19 字数 573 浏览 5 评论 0原文

我有以下代码,由于 System.Linq 版本 3.5 和 4.0 之间的“不明确调用”,它在 .Any( 之后的 lambda 表达式下显示一条波浪形的红线 - 我如何强制它使用特定版本?

它编译并 我现在已经检查了整个解决方案中的所有 (60) 个项目,并且对 System.dll 和System.Core.dll

string[] allowedExtensions = { "PNG", "JPG", "JPEG", "GIF" };
string fileExtension = (Path.GetExtension(postedFile.FileName) ?? "NULL").ToUpper().TrimStart(new[] { '.' });

if (this.MediaService.FileAllowed(postedFile) 
    && allowedExtensions.Any(e => e == fileExtension))
{ ... }

更新

的所有引用都是版本 4.0。 - 我真的不明白它从哪里得到对 3.5 的引用。

I have the following code, which shows a squiggly red line under the lambda expression after .Any( because of an "ambiguous invocation" between System.Linq versions 3.5 and 4.0 - how do I force it to use a particular version?

It compiles and runs fine.

string[] allowedExtensions = { "PNG", "JPG", "JPEG", "GIF" };
string fileExtension = (Path.GetExtension(postedFile.FileName) ?? "NULL").ToUpper().TrimStart(new[] { '.' });

if (this.MediaService.FileAllowed(postedFile) 
    && allowedExtensions.Any(e => e == fileExtension))
{ ... }

UPDATE:

I've now checked all (60) projects in the entire solution and all the references to System.dll and System.Core.dll are version 4.0 - I really can't understand where it's getting the reference to 3.5 from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖正好 2025-01-12 17:30:19

在 ReSharper 在我使用 Linq 表达式但尚未导入“System.Linq”的文件中提供“引用 System.Core”和“导入 System.Linq”后,我遇到了这个问题。当我执行 ReSharper 命令时,我收到一些错误,表明它的一部分失败了。然后我的项目中的所有 Linq 表达式在 System.Core 3.5 和 4.0 之间都是不明确的。查看我所有的 System 和 System.Core 参考资料,它们是 4.0。删除对 System.Core (4.0) 的引用会导致歧义错误消失,并使 System.Core 从该项目的引用列表中消失。当我返回重新添加 System.Core 时,虽然它没有出现在解决方案资源管理器的引用列表中,但它在“添加引用到”对话框中被选中。尝试在那里取消选中它然后重新检查它会导致出现 System.Core 已被我的项目引用的错误。我仍在修复错误,所以我不知道这是否会影响构建过程。

I had this problem after ReSharper offered to 'reference System.Core' and 'import System.Linq' in a file where I was using a Linq expression but hadn't yet imported 'System.Linq'. When I executed the ReSharper command, I got some error that part of it had failed. Then all Linq expressions in my project were ambiguous between System.Core 3.5 and 4.0. Looking at all my System and System.Core references, they were 4.0. Removing the reference to System.Core (4.0) caused the ambiguity errors to go away, and made System.Core disappear from the list of references for that project. When I went back to re-add System.Core, although it did not appear in my list of references in Solution Explorer, it was checked in the 'Add Reference to ' dialog. Attempting to un-check it there and then re-check it resulted in an error that System.Core is already referenced by my project. I'm still fixing errors so I don't know if this will affect the build process.

甜尕妞 2025-01-12 17:30:19

您可能有两个引用不同版本的模块。在项目文件中搜索这些引用并使它们保持一致 (4.0)。

You probably have two modules that reference different versions. Search the project files for those references and bring them to consistency (4.0).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文