Cysharp / MemoryPack

Zero encoding extreme performance binary serializer for C# and Unity.
MIT License
3.29k stars 193 forks source link

.net7 C#11 IMemoryPackFormatter<IPAddress>: CS8987 #173

Closed 42Entwickler closed 7 months ago

42Entwickler commented 1 year ago

Having a class Library with MemoryPack 1.9.16. After Upgrade from .net6 to .net7 the custom-formater don't compile anymore:

public class IPAddressMemoryPackFormater : IMemoryPackFormatter<IPAddress> {
    public void Deserialize(ref MemoryPackReader reader, ref IPAddress? value) {
        throw new NotImplementedException();
    }

    public void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, ref IPAddress? value) where TBufferWriter : IBufferWriter<byte> {
        throw new NotImplementedException();
    }
}

The Serialize and the Deserialize Method have the compile error CS8987: The 'scoped' modifier of parameter 'value' doesn't match overridden or implemented member.

The TargetFramework is simply .net7.0 with no special configuration. So it's the default language (C# 11)

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <RootNamespace>MYNAMESPACE</RootNamespace>
        <SignAssembly>True</SignAssembly>
        <AssemblyOriginatorKeyFile>..\MYFILE.snk</AssemblyOriginatorKeyFile>
        <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
        <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="HtmlAgilityPack" Version="1.11.51" />
        <PackageReference Include="MemoryPack" Version="1.9.16" />
        <PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.6.40" />
        <PackageReference Include="System.Security.Cryptography.ProtectedData" Version="7.0.1" />
    </ItemGroup>

</Project>

any help how to fix this?

neuecc commented 1 year ago

net 7 and others is different method signature. please see target-framework-dependency section. https://github.com/Cysharp/MemoryPack#target-framework-dependency

42Entwickler commented 1 year ago

Yea I found and tried this already. But targeting both brings me in big troubles (i only need .net7) because I use multiple features not supported when targeting .netStandard (like GC.AllocateUninitializedArray<byte>(SIZE)) or init on properties or [SupportedOSPlatform("windows")] isn't supported... And the given compile errors mentioned above still occurs. (with the new once)

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

hadashiA commented 7 months ago

Since the signature of IMemoryPackFormatter has been changed since 1.10, please change ref to scopd ref.

(Note that the Unity package is distributed with C# 9.0 source, so it is still a ref, not a scoped ref.