Repository navigation
Description
Environment details
- Programming language: C#
- OS: Ubuntu 18.04-x64
- Language runtime version: .Net 5.0
- Package version: Google.Apis.Auth v1.4.9
Steps to reproduce
- publish ASP project
dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false --output "D:\dev\Backend\src\WebApp\bin\Linux" - copy to folder on ubuntu server
\var\www\backend - start service
sudo systemctl enable kestrel-credion-backend.service
sudo systemctl start kestrel-credion-backend.service
systemctl daemon-reload - see an error on
sudo systemctl status kestrel-credion-backend.serviceand the full exception with stacktrace in logs\var\log\syslog
Details
I have an ASP Core project (.Net 5.0) with Newtonsoft.Json v13.0.1 and FirebaseAdmin v2.2.0 which uses Google.Apis.Auth v1.4.9 which depends on Newtonsoft v12.0.0.
I create build for deploy by comand dotnet publish -c Release -r ubuntu.18.04-x64 --self-contained false --output "D:\dev\Backend\src\WebApp\bin\Linux" and copy Linux folder's content into /var/www/backend.
There is service for it at /etc/systemd/system:
[Unit]
Description=Credion backend
[Service]
WorkingDirectory=/var/www/backend
ExecStart=/usr/bin/dotnet /var/www/backend/WebApp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
and after it restart service by:
sudo systemctl enable kestrel-credion-backend.service
sudo systemctl start kestrel-credion-backend.service
systemctl daemon-reload
If check status sudo systemctl status kestrel-credion-backend.service you will see an error Process: 21075 ExecStart=/usr/bin/dotnet /var/www/backend/WebApp.dll (code=killed, signal=ABRT).
For details go to log file syslog at /var/log and you can see:
Oct 19 15:15:30 credionix dotnet-example[17385]: Unhandled exception. System.InvalidOperationException: Error deserializing JSON credential data.
Oct 19 15:15:30 credionix dotnet-example[17385]: ---> System.TypeInitializationException: The type initializer for 'Google.Apis.Json.NewtonsoftJsonSerializer' threw an exception.
Oct 19 15:15:30 credionix dotnet-example[17385]: ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
Oct 19 15:15:30 credionix dotnet-example[17385]: File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Json.NewtonsoftJsonSerializer..ctor()
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Json.NewtonsoftJsonSerializer..cctor()
Oct 19 15:15:30 credionix dotnet-example[17385]: --- End of inner exception stack trace ---
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Json.NewtonsoftJsonSerializer.get_Instance()
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateDefaultCredentialFromStream(Stream stream)
Oct 19 15:15:30 credionix dotnet-example[17385]: --- End of inner exception stack trace ---
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Auth.OAuth2.DefaultCredentialProvider.CreateDefaultCredentialFromStream(Stream stream)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Auth.OAuth2.GoogleCredential.FromStream(Stream stream)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Google.Apis.Auth.OAuth2.GoogleCredential.FromFile(String path)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Credion.Domain.Providers.FirebaseMessageProvider.Setup() in D:\dev\Backend\src\.layers\Domain\Providers\Messages\FirebaseMessageProvider.cs:line 26
Oct 19 15:15:30 credionix dotnet-example[17385]: at Credion.App.Program.<>c.<CreateHostBuilder>b__3_3(IWebHostBuilder web) in D:\dev\Backend\src\WebApp\Program.cs:line 65
Oct 19 15:15:30 credionix dotnet-example[17385]: at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.<>c__DisplayClass0_0.<ConfigureWebHostDefaults>b__0(IWebHostBuilder webHostBuilder)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure, Action`1 configureWebHostBuilder)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions.ConfigureWebHost(IHostBuilder builder, Action`1 configure)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults(IHostBuilder builder, Action`1 configure)
Oct 19 15:15:30 credionix dotnet-example[17385]: at Credion.App.Program.CreateHostBuilder(String[] args) in D:\dev\Backend\src\WebApp\Program.cs:line 31
Oct 19 15:15:30 credionix dotnet-example[17385]: at Credion.App.Program.Main(String[] args) in D:\dev\Backend\src\WebApp\Program.cs:line 100
Oct 19 15:15:30 credionix systemd[1]: kestrel-credion-backend.service: Main process exited, code=killed, status=6/ABRT
Oct 19 15:15:30 credionix systemd[1]: kestrel-credion-backend.service: Failed with result 'signal'.
As we see error fires at FirebaseMessageProvider.cs:line 26 which is folowing:
26 _ = FirebaseApp.Create(
27 new AppOptions()
28 {
29 Credential = GoogleCredential.FromFile(path),
30 });
Downgrade Newtonsoft.Json or append
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<Target Name="ForceGenerationOfBindingRedirects"
AfterTargets="ResolveAssemblyReferences"
BeforeTargets="GenerateBindingRedirects"
Condition="'$(AutoGenerateBindingRedirects)' == 'true'">
<PropertyGroup>
<!-- Needs to be set in a target because it has to be set after the initial evaluation in the common targets -->
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
</Target>
didn't help.
Important remark: on Win10 and Windows Server all works fine.
Activity
jskeet commentedon Oct 19, 2021
I'd really like to try to reproduce this in a completely minimal fashion.
Two questions:
dotnet [name of dll]does it still fail? (I'd like to get all the systemd stuff out of the way if at all possible.)Mainmethod to callGoogle.Apis.Json.NewtonsoftJsonSerializer.CreateDefaultSettings(), I'd expect that to fail nice and early - does it?If you could post the answers to these questions along with a project file, that would really help.
Note that you could also add an explicit dependency on Google.Apis.Auth version 1.55.0.
EgoPingvina commentedon Oct 20, 2021
dotnet [name of dll]returns the same errorjskeet commentedon Oct 20, 2021
Excellent - that should make it simpler to test, for one thing. If we can get this down to a minimal example (which could be expressed in terms of "start with dotnet new web, then modify the project file like this, then add this code") then we'll be able to make progress.
EgoPingvina commentedon Oct 20, 2021
doesn't help too
EgoPingvina commentedon Oct 20, 2021
https://stackoverflow.com/questions/45242353/dotnet-publish-outputs-old-packages
the problem in
--outputarg ofdotnet deploy. I really hove no ideas, why when we use it, builder starts to cope old versions of dll and from where it takes them, but without--outputit works.jskeet commentedon Oct 20, 2021
Okay, that sounds very odd, but also not something specific to this library, and not something we'd be able to address here.
Best of luck with implementing the workaround.
Closing.