编程语言
首页 > 编程语言> > c#-.NET Framework 4.6.1应用程序具有引用.NET Standard 1.4类库的错误

c#-.NET Framework 4.6.1应用程序具有引用.NET Standard 1.4类库的错误

作者:互联网

我一直试图围绕.NET Framework,.NET Core和.NET Standard之间的差异进行总结.根据我的阅读,.NET Standard是最低的公分母,使用.NET Standard编写的库应该与使用其他框架编写的代码兼容.

但是,我已经创建了一个使用.NETStandard 1.4的类库和使用.NET Framework 4.6.1的应用程序的解决方案,看来该应用程序无法使用该库.

无论应用程序在哪里尝试使用类库中的类,我都会收到诸如以下的错误.

Error CS0012 The type ‘IEnumerator<>’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Error CS0012 The type ‘Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Error CS1579 foreach statement cannot operate on variables of type ‘HtmlMonkey.HtmlNodeCollection’ because ‘HtmlMonkey.HtmlNodeCollection’ does not contain a public definition for ‘GetEnumerator’

有人可以帮助我完善对这些库的理解,以便我的应用程序可以使用我的类库吗?

解决方法:

这是有关netstandard 1.4及更低版本与.NET 4.6.1-4.7项目的兼容性的已知问题.追踪到.NET Standard GitHub repo作为问题#503 Referencing NETStandard.Library 2.0.0 in net461-net47 project and only using ns1.4 (or lower) libs doesn’t work

问题的描述和解决方法如下:

NETStandard.Library 2.0.0 package doesn’t install netstandard1.x packages in net461-net47 projects. This is because we expected the support package to always be present on net461 and later, but when that support was implemented we dialed it back to only turn on when a netstandard1.5 or later library was referenced.

As a result installing a netstandard1.0-1.4 library in a net461-47 project and referencing NETStandard.Library 2.0.0 package will have missing dependencies.

One workaround is to use the NETStandard.Library 1.6.1 package instead. This still has the dependencies on the individual library packages to bring in the facades.

An alternative workaround is to set ImplicitlyExpandNETStandardFacades=true in the project file. This will enable all the facades for ns2.0 assemblies.

标签:net-standard,net-standard-1-4,net-4-6-1,c,net
来源: https://codeday.me/bug/20191110/2015527.html