Getting ambiguity issues (CS0121) with auto generated code from StrawberryShake (GraphQL)

1.2k views Asked by At

I'm getting ambiguity issues when using the auto generated code from the StrawberryShake.CodeGeneration.CSharp.Analyzers. First time using this package so I might have done something silly. The error message is

CS0121: The call is ambiguous between the following methods or properties ...

Image of error in visual studio CS0121

I've tried reinstalling the nuget package and reinstalling the tool.

For reference my project properties are as follows:

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

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Authentication.WebAssembly.Msal" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
    <PackageReference Include="Refit" Version="6.3.2" />
    <PackageReference Include="StrawberryShake.CodeGeneration.CSharp.Analyzers" Version="12.15.2" />
    <PackageReference Include="StrawberryShake.Transport.Http" Version="12.15.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\GrafanaUtilities.Shared.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Generated\" />
  </ItemGroup>

  <ItemGroup>
    <GraphQLConfig Include="Queries\Queries.graphql" />
  </ItemGroup>
</Project>

Update: I managed to get arround the error currently by flagging the generated code not to do anything during compile (It appears as though the code is being placed in some temp directory as well as in the "Generated" folder in the project.)

If there is a way to prevent the temp file that would be great to know. For anyone else facing the same issue hope this helps.

3

There are 3 answers

0
BuddhiP On BEST ANSWER

I faced the same issue, and it's annoying because when this happens VSCode can not give you IntelliSense, and the generated code is not the most readable.

In fact I don't think it generate any more files than what's in "Generated" folder, but that code is only for us to see. The actual code is generated on the fly.

This is from their getting started guide here: https://chillicream.com/docs/strawberryshake/get-started

With the project compiled you now should see a directory Generated. The generated code is just there for the IDE, the actual code was injected directly into roslyn through source generators

Therefore it should be safe to get rid of the code inside the "Generated" folder, everything works still.

You can do this by setting "emitGeneratedCode": false, in .graphqlrc.json file.

Boom, then VSCode does not complain about duplicate definitions, and IntelliSense works like a Charm.

0
Björn F On

This appears to have been fixed in StrawberryShake v13, where they use a different approach, a preview release is available now.

I was having the same issue in VS Code and Rider and have been using the comment out solution, but after upgrading I no longer need to do this.

0
Richard Whitfield On

I still have this issue in StrawberryShake 13.5.1.

I think you can also set the 'build action' to 'none' for the generated code.