dotnet / dotnet/Scaffolding

Cannot scaffold Identity due to ambiguous calls between extension methods.

Open
#2,621 5 comments 1 reaction 0 assignees View on GitHub
area-scaffolding customer-reported
Dominant language
C#
Stars
818
Forks
260
Avg merge
1d 8h
Merged PRs (30d)
10

Description

The following is taken from https://github.com/dotnet/aspnetcore/issues/53290 as I did not know there is a separate repo for scaffolding.

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

If I run `dotnet aspnet-codegenerator identity`, I get this:

```
Building project ...
Finding the generator 'identity'...
Running the generator 'identity'...
No database provider found. Using 'SqlServer' by default for new DbContext creation!
RunTime 00:00:25.44
```

This is weird because I do have a context, but this works and adds all `Areas/Identity` pages to the project. It also modifies `Program.cs` by adding the new DbContext. However, if I specify the DbContext, I get this:

```
Building project ...
Finding the generator 'identity'...
Running the generator 'identity'...
Failed to compile the project in memory
< a lot of errors >
S:\Microsoft Visual Studio\workspaceC#\SSO.NET\src\Identity.API\Program.cs(18,9): error CS0121: The call is ambiguous between the following methods or properties: 'LSAC.Services.Identity.API.Extensions.StartupExtensions.ConfigureCors(Microsoft.AspNetCore.Builder.WebApplicationBuilder)' and 'LSAC.Services.Identity.API.Extensions.StartupExtensions.ConfigureCors(Microsoft.AspNetCore.Builder.WebApplicationBuilder)'
S:\Microsoft Visual Studio\workspaceC#\SSO.NET\src\Identity.API\Program.cs(41,45): error CS0121: The call is ambiguous between the following methods or properties: 'LSAC.Services.Identity.API.Extensions.ConfigurationExtensions.GetRequiredConnectionString(Microsoft.Extensions.Configuration.IConfiguration, string)' and 'LSAC.Services.Identity.API.Extensions.ConfigurationExtensions.GetRequiredConnectionString(Microsoft.Extensions.Configuration.IConfiguration, string)'
< a lot more errors like this >
```

Due to privacy, I am only showing this, but there are around 30 errors. All errors are related to extension methods.

### Expected Behavior

The scaffolder generates code or better errors.

### Steps To Reproduce

https://github.com/Grizzlly/IdentityScaffoldBugRepro

Open in VS, add new identity scaffold, select `Override all files` (for example), select the DbContext and click add. You will get this in the logs:

```
Finding the generator 'identity'...
Running the generator 'identity'...
Failed to compile the project in memory
S:\Microsoft Visual Studio\workspaceC#\WebApplication1\Program.cs(9,46): error CS0121: The call is ambiguous between the following methods or properties: 'Extensions.ConfigurationExtensions.GetRequiredConnectionString(Microsoft.Extensions.Configuration.IConfiguration, string)' and 'Extensions.ConfigurationExtensions.GetRequiredConnectionString(Microsoft.Extensions.Configuration.IConfiguration, string)'
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
```

### Exceptions (if any)

Shown above.

### .NET Version

8.0.100

### Anything else?

.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6a1e483a

Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.100\

.NET workloads installed:
Workload version: 8.0.100-manifests.6a1e483a
[maccatalyst]
Installation Source: VS 17.8.34316.72
Manifest Version: 17.0.8478/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.0.8478\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.8.34316.72
Manifest Version: 34.0.43/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.43\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.8.34316.72
Manifest Version: 17.0.8478/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.0.8478\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.8.34316.72
Manifest Version: 8.0.3/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.3\WorkloadManifest.json
Install Type: Msi

[wasm-tools]
Installation Source: VS 17.8.34316.72
Manifest Version: 8.0.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.0\WorkloadManifest.json
Install Type: Msi

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
6.0.202 [C:\Program Files\dotnet\sdk]
8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-rc.1.21451.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.