error CS0246: The type or namespace name ‘Newtonsoft’ could not be found (are you missing a using directive or an assembly reference?)

I’m trying to dockerize a .net api project which runs on .netframework version 4.7.2. I can run the application locally with no issues , but when i try to dockerize the same source code I’m getting the above error

The docker build fails at msbuild command

Docker file:

# start with a base image with all the necessary tooling to compile our app
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build

# set the working directory inside compilation container to c:\app
WORKDIR /app
COPY . .

# setting up RSA key
WORKDIR C:/Windows/Microsoft.NET/Framework64/v4.0.30319
RUN aspnet_regiis -pi CoreconKeys "/app/keys.xml"
WORKDIR /app
ARG npm_token 
ENV npm=${npm_token}

# restore nuget packages
RUN nuget restore

# use msbuild to publish project to c:\publish
RUN msbuild .\Corecon_API.sln /p:DeployOnBuild=true /property:Configuration=Release /p:PublishProfile=FolderProfile /p:PublishUrl="c:\publish"

FROM mcr.microsoft.com/windows/servercore/iis
RUN powershell Install-WindowsFeature NET-Framework-45-ASPNET ; \  
Install-WindowsFeature Web-Asp-Net45 ; Install-WindowsFeature Web-Windows-Aut

WORKDIR /inetpub/wwwroot
# copy files from bin/publish in our sdk container into c:\inetpub\wwwroot
COPY --from=build /publish. ./

Error message:
click here

"C:\app\Corecon API.sin" (default target) (1) ->
"C:\app\CoreconlebApi2\CoreconWebApi2.csproj" (default target) (20) ->
"C:\app\CoreconwebApi.Integration.Stratosphere\CoreconwebApi.Integration.Stratosphere.csproj"(defaulttarget)(22:2) ->
(CoreCompile target) ->
  C:\app\CoreconWebApi.Integration.Stratosphere\Parser.cs(2,7): error C50246: The type or namespace name "Newtonsoft" could not be found (are you missing a using directive or an assembly reference?) [C:\app\CoreconWlebApi.Integration.Stratosphere\CoreconWebApi.Integration.Stratosphere.csproj]
  C:\app\CoreconWebApi.Integration.Stratosphere\StratoService.cs(10,7):error CS0246: The tvpe or namespace name "Newtonsoft" could not be found (are vou missing a using directive or an assembly reference?) C:\app\CoreconwebApi.Integration.Stratosphere\CoreconWebApi.Integration.Stratosphere.csproj

    200 Warning(s)
    2 Error(s)

I can find all the packaged got restored inside container under the packages folder after nuget restore

I’m expecting to build a docker image out of this!!

  • Don’t add code/messages as images

    – 

  • You may have more than one sln file. Sometimes you have an sln in the parent folder and main folder. I would open project by double clicking on the csproj file and rebuild which may create a new sln. Also open csproj file with notepad and check if NewtonSoft is in the csproj file.

    – 

  • Just for infomration: error codes that start with CS are C# compiler errors. An MSBuild error would be prefixed with MSB.

    – 

  • You stated that “I can find all the packaged got restored inside container under the packages folder after nuget restore”. You confirmed that the NuGet packages folder contains the NewtonSoft package? Is the .csproj using a packages.config file or is it using a PackageReference for NewtonSoft?

    – 

Leave a Comment