0

I have installed .NET 6 Preview 7 successfully. I have access to System.IAdditionOperators<,,>. My problem is that when I try to implement the interface it doesn't require me to define the + operator.

My project file:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <PropertyGroup>
    <EnablePreviewFeatures>true</EnablePreviewFeatures>
    <LangVersion>preview</LangVersion>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.Runtime.Experimental" Version="6.0.0-preview.7.21377.19" />
  </ItemGroup>

</Project>

My one and only class:

using System;

namespace TestCode
{
    public class Foo:IAdditionOperators<Foo,Foo,Foo>
    {
    }
}

The code compiles (which it shouldn't!) even though I haven't implemented IAdditionOperators<Foo,Foo,Foo>. How do I make it force me to implement the + operator?

I have already downloaded the SDK, and updated Visual Studio to version 16.11.4. I have already checked the box for "Use preview of the .NET SDK" and restarted Visual Studio. What else do I have to do?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Nigel
  • 2,961
  • 1
  • 14
  • 32
  • According to the [source](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IAdditionOperators.cs), these are `static` operators, so I would imagine the usual implementation constraints don't apply. You could file a feature request/bug report. – Robert Harvey Oct 06 '21 at 18:10
  • You can find a related discussion from 2008 about `abstract` `static` interface members [here](https://stackoverflow.com/q/3284/102937). – Robert Harvey Oct 06 '21 at 18:11

1 Answers1

1

To make the compilation fail you need either to use dotnet build from terminal or install VS 2022 Preview (I had the same problem for this answer). As for the code compiled by VS 2019 - it should fail in runtime when you try to start your application.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132