microsoft / Microsoft.IO.RecyclableMemoryStream

A library to provide pooling for .NET MemoryStream objects to improve application performance.
MIT License
1.98k stars 205 forks source link

CS0012 on xamarinmac20 Tartget #158

Closed workgroupengineering closed 3 years ago

workgroupengineering commented 3 years ago

Current behavior

When using RecyclableMemoryStream in a Tartget target project, the compiler reports the following errors:

CS0012  The type 'MemoryStream' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
CS0012  The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

Aspected behavior

should compile without errors.

Environment:

Visual Studio: Visual Studio Community 2019 Build 16.9.4+31205.134 RecyclableMemoryStream Version: 2.0.0

paulomorgado commented 3 years ago

Have you tried adding a reference to netstandard 2.1.0.0, as suggested?

workgroupengineering commented 3 years ago

I edited the project file as you suggested and now it works.

I think it is better to add targets to library without adding trick.

<Project Sdk="MSBuild.Sdk.Extras" ToolsVersion="15.0">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.1;xamarinmac20;xamarinios10;MonoAndroid11.0;MonoAndroid10.0</TargetFrameworks>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <PackageReference Include="System.Buffers" Version="4.5.1" />
    <PackageReference Include="System.Memory" Version="4.5.4" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.0.0" />    
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'xamarinmac20'">    
    <Reference Include="netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
  </ItemGroup>

</Project>
paulomorgado commented 3 years ago

This is not a trick. This is how it works.

You can get the same for .NET Standard on other targets.

Adding those targets to the library is not the solution. Otherwise, we should add them all. That's what .NET Standard is for. To avoid all that.

workgroupengineering commented 3 years ago

Hi, I think it is a trick because adding the reference is not possible from the ide and only those who know a little about how msbuild ItemGroup work can solve it easily.

paulomorgado commented 3 years ago

Hi, I think it is a trick because adding the reference is not possible from the ide and only those who know a little about how msbuild ItemGroup work can solve it easily.

That would be a shortcoming of the IDE.

Which IDE are you using?

workgroupengineering commented 3 years ago

Microsoft Visual Studio Community 2019 Version 16.9.4

immagine

paulomorgado commented 3 years ago

You should report that through "Report a problem".