Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: dotnet restore Fails with NullReferenceException in .NET SDK 9.0.100 During Docker Build #44841

Open
InvixGG opened this issue Nov 13, 2024 · 0 comments
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@InvixGG
Copy link

InvixGG commented Nov 13, 2024

Describe the bug

When attempting to build a Docker image for a .NET application using the .NET SDK 9.0.100 Docker image, the dotnet restore command fails with a System.NullReferenceException. The error originates from the Message task within MSBuild, indicating an internal issue with the SDK's build process.

Steps To Reproduce

Github Actions:

name: Build and Push Docker Images to GHCR

on:
  push:
    branches:
      - main

jobs:
  build-and-push:
    runs-on: self-hosted
    permissions:
      contents: read
      packages: write

    steps:
      # Step 1: Checkout the repository
      - name: Checkout
        uses: actions/checkout@v4

      # Step 2: Setup Docker Buildx
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      # Step 3: Login to GitHub Container Registry
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # Step 4: Build and Push Multi-Platform Docker Images
      - name: Build and Push Multi-Platform Docker Images
        run: |
          docker buildx build --platform linux/arm64 `
            -f "src/App/Dockerfile" `
            -t ghcr.io/vexel-studios/app-app:${{ github.run_number }} `
            -t ghcr.io/vexel-studios/app-app:latest `
            --push .

App.csproj:

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

    <PropertyGroup>
        <TargetFramework>net9.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <LangVersion>latestmajor</LangVersion>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
        <VersionPrefix>1.0.0</VersionPrefix>
        <VersionSuffix>beta.12</VersionSuffix>
        <FileVersion>$(VersionPrefix)</FileVersion>
        <AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
        <Configurations>Development;Production</Configurations>
        <Platforms>AnyCPU</Platforms>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Development' ">
        <DefineConstants>DEVELOPMENT</DefineConstants>
        <DebugSymbols Condition=" '$(DebugSymbols)' == '' ">true</DebugSymbols>
        <Optimize Condition=" '$(Optimize)' == '' ">false</Optimize>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Production' ">
        <DefineConstants>PRODUCTION</DefineConstants>
        <Optimize Condition=" '$(Optimize)' == '' ">true</Optimize>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02410" />
        <PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02410" />
        <PackageReference Include="Hangfire" Version="1.8.15" />
        <PackageReference Include="Hangfire.AspNetCore" Version="1.8.15" />
        <PackageReference Include="Hangfire.PostgreSql" Version="1.20.10" />
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.0-rc.2" />
        <PackageReference Include="Sentry" Version="4.13.0" />
        <PackageReference Include="Sentry.AspNetCore" Version="4.13.0" />
        <PackageReference Include="Sentry.Extensions.Logging" Version="4.13.0" />
        <PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
        <PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.4" />
        <PackageReference Include="System.Linq.Async" Version="6.0.1" />
    </ItemGroup>
    
    <ItemGroup>
      <Compile Update="src\DataBase\Models\WarningConfiguration.cs">
        <DependentUpon>Warning.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\MessageConfiguration.cs">
        <DependentUpon>Message.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\InquiryConfiguration.cs">
        <DependentUpon>Inquiry.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\InquiryUserConfiguration.cs">
        <DependentUpon>InquiryUser.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\MemberConfiguration.cs">
        <DependentUpon>Member.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\ProgressConfiguration.cs">
        <DependentUpon>Progress.cs</DependentUpon>
      </Compile>
      <Compile Update="src\DataBase\Models\ProgressMessageConfiguration.cs">
        <DependentUpon>ProgressMessage.cs</DependentUpon>
      </Compile>
    </ItemGroup>

    <ItemGroup>
        <Content Include="src\Resources\Images\DiscordJoinBanner.png">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <None Remove="badwords.txt" />
        <Content Include="badwords.txt">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <None Remove="src\Resources\Fonts\MADE-TOMMY-Medium.otf" />
        <Content Include="src\Resources\Fonts\MADE-TOMMY-medium.otf">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
        <None Remove="src\Resources\Fonts\MADE-TOMMY-regular.otf" />
        <Content Include="src\Resources\Fonts\MADE-TOMMY-regular.otf">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

    <ItemGroup>
      <None Remove="src\Resources\Images\DiscordJoinBanner.png" />
    </ItemGroup>

</Project>

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:9.0-bookworm-slim-arm64v8 AS base
USER $APP_UID
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim-arm64v8 AS build
ARG BUILD_CONFIGURATION=Production
ENV ASPNETCORE_ENVIRONMENT=Production
WORKDIR /src
COPY ["src/App/App.csproj", "src/App/"]
RUN dotnet restore "src/App/App.csproj"
COPY . .
WORKDIR "/src/src/App"
RUN dotnet build "App.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ENV ASPNETCORE_ENVIRONMENT=Production
RUN dotnet publish "App.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "App.dll"]

Exceptions (if any)

/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(93,5): error MSB4018: The "CheckIfPackageReferenceShouldBeFrameworkReference" task failed unexpectedly. [/src/src/App/App.csproj]
/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(93,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/src/src/App/App.csproj]
/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(93,5): error MSB4018:    at InvokeStub_CheckIfPackageReferenceShouldBeFrameworkReference.set_FrameworkReferences(Object, Object, IntPtr*) [/src/src/App/App.csproj]
/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(93,5): error MSB4018:    at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) [/src/src/App/App.csproj]
/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(95,7): error MSB4026: The "FrameworkReferences=@(FrameworkReference)" parameter for the "CheckIfPackageReferenceShouldBeFrameworkReference" task is invalid. [/src/src/App/App.csproj]
/usr/share/dotnet/sdk/9.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets(93,5): error MSB4063: The "CheckIfPackageReferenceShouldBeFrameworkReference" task could not be initialized with its input parameters.  [/src/src/App/App.csproj]

.NET Version

9.0.100

Anything else?

IDE:
JetBrains Rider 2024.3 RC 1

Dotnet info:

.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.3068a692
 MSBuild version:   17.12.7+5b8665660

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

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  7.0.203 [C:\Program Files\dotnet\sdk]
  8.0.110 [C:\Program Files\dotnet\sdk]
  8.0.403 [C:\Program Files\dotnet\sdk]
  9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.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:
  D:\Documents\Invix Digital\Companies\Vexel Studios\Discord Bot\Project\global.json

Original issue

dotnet/aspnetcore#58907

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant