Closed klyse closed 2 years ago
EDIT: having a detailed .dockerignore
makes absolutely sense, but did not solve my issue. The test I made was on a wrong branch.
Found the solution myself. The .dockerignore
did not exclude build results and therefore copied the binaries into the container which led to this issue.
Here is the .dockerignore
that worked for us:
Web/appsettings.[Dd]evelopment.json
*.env
.envrc
.git
.dockerignore
.gitignore
.vs
.vscode
docker-compose.yml
docker-compose.*.yml
*/bin
*/obj
Having the correct .dockerignore
did not solve the issue it just stays the same.
I made the test on a wrong branch. Sorry for the confusion.
After some more hours of debugging I found the problem. Finally.
Here is a repo to reproduce the problem: https://github.com/klyse/Serilog-Version-Bug
A lib targeting netstandard2.0
loaded Serilog 2.10.0
while the main project targets net5/6.0
and loadedSerilog.AspNetCore 4.1.0
. CreateBootstrapLogger()
then tries to resolve a wrong dll and the app does not start.
@klyse , interesting...
It looks like the published version of Serilog.dll
comes from netstandard2.0
package folder instead of netstandard2.1
.
Can you check this via reflection tool like ILSpy
?
And web.deps.json
should look like
"Serilog/2.10.0": {
"runtime": {
"lib/netstandard2.1/Serilog.dll": {
"assemblyVersion": "2.0.0.0",
"fileVersion": "2.10.0.0"
}
}
}
Is it happens only from docker environment? Looks like a tooling issue, could not reproduce it yet.. (unless manually copy Serilog.dll
of netstandard2.0
to the output folder)
Ok, just change the line
dotnet publish -c Release -o out
to
dotnet publish web -c Release -o out
I read somewhere that publish
on .sln
is not a recommended way because can have unpredicted results. (Lib
published artifacts overwrites Web
artifacts). At least, in current tooling (check dotnet/sdk
) .
Instead, do your publish just for the end project (Web.csproj
)
That did the trick! This is awesome, thanks @skomis-mm! I guess the ILSpy
is not required anymore.?
@klyse Great!
No, ILSpy
is not required anymore :)
Installed nuget packages
Also tried with a more minimalistic set of nugets:
OS
Docker
mcr.microsoft.com/dotnet/aspnet:5.0
Additional Information
ASP.Net Core 5.0 app running in a docker container
Code
Exception
Steps tried to resolve the issue
appsettings.*.json
mcr.microsoft.com/dotnet/aspnet:5.0.12
,mcr.microsoft.com/dotnet/aspnet:5.0.5
and some more--no-cache
Hint to where the problem comes from
When changing
.CreateBootstrapLogger()
toCreateLogger()
and adjustingCreateHostBuilder
of course the issue is gone.