microsoft/dotnet-apiport

MemoryCache is reported incompatible with netstandard2.0

zitcomdev opened this issue · 6 comments

According to https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-3.1
System.Runtime.Caching/MemoryCache should be compatible with .NET Standard 2.0.
However, running the Portability Analyzer (https://docs.microsoft.com/en-us/dotnet/standard/analyzers/portability-analyzer), it is reported that it is not supported in .NET Standard 2.0 (without platform extensions).

Also tried the Microsoft.Extensions.Caching.Memory instead, with the same result.

What does this mean - is there a bug in the analyzer, or in the documentation, or am I reading it incorrectly ?

Just discovered: This also happens with Newtonsoft.Json.Linq.JObject.
How reliable is the analyzer ? How should it be used ?

@zitcomdev I think that Portability Analyzer's report is correct. BTW, it uses the same API data as https://apisof.net/ and .NET API Browser.

System.Runtime.Caching/MemoryCache should be compatible with .NET Standard 2.0.
However, running the Portability Analyzer (https://docs.microsoft.com/en-us/dotnet/standard/analyzers/portability-analyzer), it is reported that it is not supported in .NET Standard 2.0 (without platform extensions).
When Portability Analyzer reports it is not support in .NET Stardard 2.0, it means that the API is not part of .NET Stardard 2.0, which is accurate. the document at https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-3.1 states that "it can be used with: .NET Standard 2.0 or later.", which is also correct. There is subtle difference between an API is part of .NET standard 2 vs it can be used with .NET Standard. The later means that even though the API is not part of the .NET Standard, but it doesn't reply on any API beyond .NET Standard. From customer accessing app .NET Core portability purpose, either of these two cases are good news. Hope this helps to explain what you see.

Closing the issue for now. Please feel free to reopen of you have further problem.

But that doesn't really address the issue. The documentation says that the MemoryCache should be compatible with .NET Standard 2.0 - why does the analyzer report otherwise ? Does that mean it actually isn't compatible ? Not sure what to trust here.

But that doesn't really address the issue. The documentation says that the MemoryCache should be compatible with .NET Standard 2.0 - why does the analyzer report otherwise ? Does that mean it actually isn't compatible ? Not sure what to trust here.
@zitcomdev it is very fair question. First thing to clarify is that if .NET portability Aanalyzer reported correctly? Does its report align with the document at https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-3.1. The answer is yes. Per windows compatability pack (platform extensions) doc at https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/connect/net-introducing-the-windows-compatibility-pack-for-net-core, System.Runtime.Caching component belongs to windows compatability pack (platform extensions). Also, as I mentioned in early reponse, MemoryCache is not part of the .NET Standard 2.0, but build on top of .NET Stardard 2.0, which is consistent with doc's statement "it can be used with: .NET Standard 2.0 or later.". However, the question really comes to what's the definition of ".NET Standard" vs ".NET Starndard+platform extensions"? Why developer as the API user cares about the difference, and how should they use them differently? @terrajobst and @ericstj, can you common on this?

For clarity:
If I create a .NET standard 2.1 project and add the NuGet package for System.Runtime.Caching (which has a .net standard 2.1 target), can I then use MemoryCache the same way I did in the .netframework 4.7.2?

Closing as API Port was deprecated in favor of binary analysis in .NET Upgrade Assistant.