domn1995/dunet

Problem on the basic usage.

Closed this issue · 8 comments

Hi, I've tried to use the basic usage on my machine with SDK .net 6.0.100, but I cannot compile due to the following errors:

  • Program.cs(13, 2): [CS0246] The type or namespace name 'UnionAttribute' could not be found (are you missing a using directive or an assembly reference?);
  • Program.cs(13, 2): [CS0246] The type or namespace name 'Union' could not be found (are you missing a using directive or an assembly reference?);

This is my cproj and my Program.cs:

`

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Dunet" Version="1.0.0" />
</ItemGroup>

`

`using Dunet;

var shape = new Shape.Rectangle(3, 4);
var area = shape.Match(
circle => 3.14 * circle.Radius * circle.Radius,
rectangle => rectangle.Length * rectangle.Width,
triangle => triangle.Base * triangle.Height / 2
);
Console.WriteLine(area);

[Union]
partial record Shape
{
partial record Circle(double Radius);
partial record Rectangle(double Length, double Width);
partial record Triangle(double Base, double Height);
}`

What I'm missing?

Are these errors from visual studio or from running dotnet build on the terminal? If it's from Visual Studio, a simple restart should fix it:

dotnet/roslyn#49249 (comment)

dotnet/roslyn#48083

They are both on Terminal or Rider. I'm on a MacOS; maybe I'm missing some required steps to build projects with Roslyn?

Sorry I don't have experience with Mac or Rider, but it does seem like source generators might still be broken on Rider: https://youtrack.jetbrains.com/issue/RIDER-58919

Could you upload the code you're trying to build as a repo to github? I'd like to clone it down and see if it builds for me on Windows and VS. If it does, that tells us it's probably something with Mac and/or Rider.

Sounds like there's also a bug with Rider where source generators don't run when you have analyzers disabled: https://youtrack.jetbrains.com/issue/RIDER-65505/Source-Generators-dont-run-when-Roslyn-Analyzers-are-disabled

Thanks for the investigation; I'll look forward to the article you reported.
I've created and shared w/ you the repository here is the link: https://github.com/VincenzoCarlino/DebugDunet36

Thanks for the investigation; I'll look forward to the article you reported. I've created and shared w/ you the repository here is the link: https://github.com/VincenzoCarlino/DebugDunet36

I was able to clone and run this with both visual studio and the windows terminal. It looks like it's most likely a Mac and/or Rider issue. I am on SDK 6.0.301, though.

Like a dumb, I've forgotten to have set SDK 7-preview as default (and global.json did not affect rider build). I've set default SDK 6.0.301, and all worked properly.

Thank you for the support, and I'm sorry I wasted your time.

No worries. Glad you got it working!