microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

ENC1002 Cannot apply changes. Unexpected error: 'An item with the same key has already been added. Key: 420' #400

Closed giuseppe-terrasi closed 10 months ago

giuseppe-terrasi commented 10 months ago

After updating Visual Studio 2022 Community to version 17.7.3 I get this compilation error if I change the source code of a dockerized Blazor server app. If I change an HTML portion the update works well. This didn't happen with the previous version.

This is my configuration:

Microsoft Visual Studio Community 2022
Versione 17.7.3
VisualStudio.17.Release/17.7.3+34024.191
Microsoft .NET Framework
Versione 4.8.09032

Thanks

NCarlsonMSFT commented 10 months ago

@giuseppe-terrasi I'm not able to reproduce this, can you please provide more details on the scenario?

For reference:

giuseppe-terrasi commented 10 months ago

@NCarlsonMSFT Thanks for your reply. I noticed that it happens only with a specific portion code of the same file. I isolated the problem inside a method containing a gRPC server streaming call with an async foreach loop.

This is the method and if I make any changes in any part of it I get the error:

private async Task LoadDataAsync()
{
    try
    {
        var serverData = new List<Data>();

        var client = new DataService.DataServiceClient(url);
        var request = client.GetData(new Request());

        await foreach (var data in request.ResponseStream.ReadAllAsync())
        {
            serverData.Add(data);
            userSearchRequest.Id = session.UserId;
        }

        if (!string.IsNullOrEmpty(successTitle) || !string.IsNullOrEmpty(successMessage)) 
        {
            NotificationService.NotifySuccess(successTitle, successMessage);
        }
    }
    catch(Exception ex)
    {
        Logger.LogError(ex, "An error occurred");

        if(!string.IsNullOrEmpty(errorMessage))
        {
            NotificationService.NotifyError(detail: errorMessage);
        }
    }
}
giuseppe-terrasi commented 10 months ago

Update: the problem seems to be related to the async foreach, the error is not present if I comment the entire foreach but it occurs even if the foreach is empty

NCarlsonMSFT commented 10 months ago

@giuseppe-terrasi does this only repro in the case of a container, or does it also happen when running locally?

giuseppe-terrasi commented 10 months ago

It only happens when running on a container, locally it works fine

NCarlsonMSFT commented 10 months ago

@giuseppe-terrasi Good news: I was able to reproduce the error. Less good news: I get the same behavior when running outside a container, so I am not the person to help you 🫤.

I'll reach out to my contacts on the debugger team and see if they can help.

tmat commented 10 months ago

Tracked by https://github.com/dotnet/roslyn/issues/69805

NCarlsonMSFT commented 10 months ago

Tracked externally