在面向.NET 4.6.2的项目中,如何实现.NET Standard 1.5程序集中定义的接口?

时间:2022-09-02 12:32:08

I have 2 separate projects, lets call them Alpha and Bravo.

我有两个独立的项目,我们称之为Alpha和Bravo。

Project Alpha targets only the net462 framework in its project.json file, while project Bravo targets only netstandard1.5. Those 2 frameworks are compatible according to Microsoft.

Project Alpha仅针对其project.json文件中的net462框架,而项目Bravo仅针对netstandard1.5。根据微软的说法,这两个框架是兼容的。

Project Alpha references project Bravo's assembly. In particular, Alpha needs to implement an interface defined in Bravo. Let's call this interface IProblematic. This interface deals mostly with headers stuff, and defines methods like this

Project Alpha参考项目Bravo的装配。特别是,Alpha需要实现Bravo中定义的接口。我们称此接口为IProblematic。这个接口主要处理头文件,并定义这样的方法

bool DoStuff(List<KeyValuePair<string, IEnumerable<string>>> requestHeaders, List<string> rolesList)

Project Alpha declares a class that implements that interface.

Project Alpha声明了一个实现该接口的类。

public bool DoStuff(List<KeyValuePair<string, IEnumerable<string>>> requestHeaders, List<string> rolesList)  {... }

So far so good. But during runtime I get plagued by errors such as Unable to load one or more of the requested types. I believe the source of the errors comes from the Collection types.

到现在为止还挺好。但是在运行时期间,我受到诸如无法加载一个或多个请求类型之类的错误的困扰。我相信错误的来源来自Collection类型。

Using Visual Studio's "go to definition" feature, I can see that project Alpha (the 462 project) is using System.Collections.Generic defined in ..\Framework\v4.0.30319\mscorlib.dll, while if I do the same in project Bravo's collections, it shows me that it is using System.Collections.Generic, defined in ..\netstandard1.3\System.Collections.dll.

使用Visual Studio的“转到定义”功能,我可以看到项目Alpha(462项目)正在使用.. \ Framework \ v4.0.30319 \ mscorlib.dll中定义的System.Collections.Generic,而如果我在项目Bravo的集合,它告诉我它正在使用System.Collections.Generic,在.. \ netstandard1.3 \ System.Collections.dll中定义。

Thus, my question is, how can I get project Alpha to use the correct Collections assembly when implementing the netstandard1.5 interface, as opposed to using mscorlib's collections? Shouldn't this even be a non-issue, given that the 2 frameworks are compatible?

因此,我的问题是,在实现netstandard1.5接口时,如何使用项目Alpha来使用正确的集合程序集,而不是使用mscorlib的集合?鉴于2个框架是兼容的,这不应该是一个非问题吗?

Thank you all in advance!

谢谢大家!

1 个解决方案

#1


0  

After some investigation I have found out that the problem is happening because my net462 app is (indirectly) depending on System.Collections.Immutable: "1.3.0 and my netstandard1.5 library has a dependency on "NETStandard.Library": "1.6.0". I will create a more focused thread with more code and stack traces on it. I apologize for the delay in getting back.

经过一些调查后我发现问题正在发生,因为我的net462应用程序(间接)取决于System.Collections.Immutable:“1.3.0并且我的netstandard1.5库依赖于”NETStandard.Library“:”1.6 .0“。我将创建一个更集中的线程,上面有更多的代码和堆栈跟踪。我为延迟回来而道歉。

#1


0  

After some investigation I have found out that the problem is happening because my net462 app is (indirectly) depending on System.Collections.Immutable: "1.3.0 and my netstandard1.5 library has a dependency on "NETStandard.Library": "1.6.0". I will create a more focused thread with more code and stack traces on it. I apologize for the delay in getting back.

经过一些调查后我发现问题正在发生,因为我的net462应用程序(间接)取决于System.Collections.Immutable:“1.3.0并且我的netstandard1.5库依赖于”NETStandard.Library“:”1.6 .0“。我将创建一个更集中的线程,上面有更多的代码和堆栈跟踪。我为延迟回来而道歉。