C
C#2mo ago
yoush

✅ OneOf library code generation not working?

I'm trying to set up the https://github.com/mcintyre321/OneOf library. Wanted to try the class generator example, and installed that part as well as the base OneOf library
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271" />
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="OneOf.SourceGenerator" Version="3.0.271" />
Running into an issue when trying to run the example code they listed https://github.com/mcintyre321/OneOf?tab=readme-ov-file#oneofbase-source-generation the red squiggly is under StringOrNumber :
C#
[GenerateOneOf]
public partial class StringOrNumber : OneOfBase<string, int> { }
C#
[GenerateOneOf]
public partial class StringOrNumber : OneOfBase<string, int> { }
There is no argument given that corresponds to the required parameter 'input' of 'OneOfBase<string, int>.OneOfBase(OneOf<string, int>)' new to source code generation related stuff and C#, help is appreciated, thank you!
8 Replies
Aaron
Aaron2mo ago
you probably just need to restart your IDE
FusedQyou
FusedQyou2mo ago
$vsdrunk
MODiX
MODiX2mo ago
* close VS * remove the hidden folder .vs * remove all bin and obj folder next to each csproj (DO NOT TOUCH THE .git FOLDER OR WHAT'S INSIDE) * restart vs
FusedQyou
FusedQyou2mo ago
Removing the .vs folder is probably enough
yoush
youshOP2mo ago
I'm on vscode so I don't have a .vs folder, I removed the bin and obj folders and tried running the project but it seems like the generator itself is failing: CSC : warning CS8785: Generator 'OneOfGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName '<global namespace>_StringOrNumber.g.cs' contains an invalid character '<' at position 0. (Parameter 'hintName')'. I also tried running it in rider and I'm also getting the same issues
jcotton42
jcotton422mo ago
Is StringOrNumber within a namespace? Try putting it in one, seems like a bug in the SG.
yoush
youshOP2mo ago
yeah this fixed it, thanks for the help!
jcotton42
jcotton422mo ago
I’d file a bug in the OneOf repo then.

Did you find this page helpful?