question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot `dotnet format` ASP.NET Core projects

See original GitHub issue

After upgrading to 6.0.2 (6.0.200) I got errors when trying to format projects using the web SDK, i.e.

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

Initially I assumed that I had something wrong or unexpected in the project I was working on and/or in my environment, as the error is basically the same as that in https://github.com/dotnet/format/issues/1500; unfortunately in my case even removing all other SDKs did not fix the issue.

EDIT: since the report, new docker images have been released; the reproducer is now much simpler: https://github.com/dotnet/format/issues/1519#issuecomment-1043607496

I tried to reproduce it using one of the standard docker images, but the latest ones are 6.0.102, not 6.0.200, so I wrote this Dockerfile. Its first stage is based on https://github.com/dotnet/dotnet-docker/blob/17971807fc0f4ff5a0eca53deb2d85fff990d95c/src/sdk/6.0/bullseye-slim/amd64/Dockerfile updating just DOTNET_SDK_VERSION and dotnet_sha512 The second stage is the actual reproducer: it creates a simple webapp (from the template) and tries to format it

ARG REPO=mcr.microsoft.com/dotnet/aspnet
FROM $REPO:6.0.2-bullseye-slim-amd64 AS sdk-6.0.200

ENV \
    # Unset ASPNETCORE_URLS from aspnet base image
    ASPNETCORE_URLS= \
    # Do not generate certificate
    DOTNET_GENERATE_ASPNET_CERTIFICATE=false \
    # Do not show first run text
    DOTNET_NOLOGO=true \
    # SDK version
    DOTNET_SDK_VERSION=6.0.200 \
    # Enable correct mode for dotnet watch (only mode supported in a container)
    DOTNET_USE_POLLING_FILE_WATCHER=true \
    # Unset Logging__Console__FormatterName from aspnet base image
    Logging__Console__FormatterName= \
    # Skip extraction of XML docs - generally not useful within an image/container - helps performance
    NUGET_XMLDOC_MODE=skip \
    # PowerShell telemetry for docker image usage
    POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetSDK-Debian-11

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        curl \
        git \
        wget \
    && rm -rf /var/lib/apt/lists/*

# Install .NET SDK
RUN curl -fSL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-linux-x64.tar.gz \
    && dotnet_sha512='334f3ea4bfeb736bed61c5896796a09d640b0ae74605c514edc5869c395befb7cfc795b58c922f14560e7d41c89c073c62ed01eefc6d9f13aa916e3478949c24' \
    && echo "$dotnet_sha512  dotnet.tar.gz" | sha512sum -c - \
    && mkdir -p /usr/share/dotnet \
    && tar -oxzf dotnet.tar.gz -C /usr/share/dotnet ./packs ./sdk ./sdk-manifests ./templates ./LICENSE.txt ./ThirdPartyNotices.txt \
    && rm dotnet.tar.gz \
    # Trigger first run experience by running arbitrary cmd
    && dotnet help

# Install PowerShell global tool
RUN powershell_version=7.2.1 \
    && curl -fSL --output PowerShell.Linux.x64.$powershell_version.nupkg https://pwshtool.blob.core.windows.net/tool/$powershell_version/PowerShell.Linux.x64.$powershell_version.nupkg \
    && powershell_sha512='bfd0fac3fe5e905156d28433dbf4978d5cea69a4f1b63cb5b8d903f865f0febf4a1b0476a5b84a8e3509b354c44b0cd9e79b31a105176f03b90693ff51c7bb0b' \
    && echo "$powershell_sha512  PowerShell.Linux.x64.$powershell_version.nupkg" | sha512sum -c - \
    && mkdir -p /usr/share/powershell \
    && dotnet tool install --add-source / --tool-path /usr/share/powershell --version $powershell_version PowerShell.Linux.x64 \
    && dotnet nuget locals all --clear \
    && rm PowerShell.Linux.x64.$powershell_version.nupkg \
    && ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \
    && chmod 755 /usr/share/powershell/pwsh \
    # To reduce image size, remove the copy nupkg that nuget keeps.
    && find /usr/share/powershell -print | grep -i '.*[.]nupkg$' | xargs rm

# my reproducer

FROM sdk-6.0.200 AS my-test

WORKDIR /app
RUN dotnet new webapp
RUN dotnet format -v diag --verify-no-changes

This reliably reproduces the issue and results in the errors:

Unhandled exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

I am unsure if this is actually a dotnet format problem or some kind of packaging issue of the SDK. In the second case, sorry for the noise 😇

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:49
  • Comments:36 (4 by maintainers)

github_iconTop GitHub Comments

60reactions
niemyjskicommented, Feb 23, 2022

Is there an eta for a fix on this? There are a lot of issues being opened and this seems like a blocking issue for many.

46reactions
jmarolfcommented, Mar 14, 2022

This will be fixed tin the 6.0.202 SDK release. I will leave this issue open until that release is downloadable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using dotnet format Command to Format the C#/.NET Code
In this article we'll discuss the use of dotnet format, to enforce consistent coding standards across operating systems and IDEs.
Read more >
How to use dotnet format to format the whole project inside ...
Net 5 app and want to use dotnet format. First I added commitlint, husky and lint-staged to the repository. The folder structure looks...
Read more >
Troubleshoot .NET Framework targeting errors
Open Solution Explorer. · Select Show All Files. · Expand My Project (Visual Basic) or Properties (C#), and then edit the Resources.resx file...
Read more >
NETSDK1045: The current .NET SDK does not support ...
This error occurs when the build tools can't find the version of the .NET SDK that's needed to build a project. This is...
Read more >
Dotnet-format not running in Github Action due to missing ...
the job fails with following error: Run dotnet format --verify-no-changes dotnet format --verify-no-changes shell: C:\Program Files\PowerShell\ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found