Serilog.Sinks.PostgreSQL is not working along with Npgsql package version 4.0.0 - postgresql

In my ASP.Net Core application, a Serilog.Sinks.PostgreSQL sink works fine along with Npgsql package version lower then 4.0.0, but it does not work along with Npgsql package version 4.0.0.
Along with Npgsql package version 4.0.0 it does not save log events into the database nor throw any exceptions into the SelfLog.
Have you got a same experience? Thanks.

Related

Why can't I install Microsoft.EntityFrameworkCore.Sqlite?

I am following this tutorial:
https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?tabs=visual-studio
I am immediately stopped because I can not complete the following command:
Install-Package Microsoft.EntityFrameworkCore.Sqlite
This is the error:
Could not install package 'Microsoft.EntityFrameworkCore.Sqlite.Core 7.0.0'. You are trying to install a package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I am attempting to learn how to use the Entity Framework and so I don't know much regarding this. Any advice would be helpful even if it's a link to something I need to read.
About the tutorial
The tutorial is about .netCore but in the error message you can see that you created a .netFramework project '.NETFramework,Version=v4.7.2'.
Create a new console application, but don't select projects that have (.NET Framework) in the description.
About the Sqlite package (only if continue the practicing with .netFramework)
The command Install-Package Microsoft.EntityFrameworkCore.Sqlite will try to install the last version. Currently, the last version is 7.0.0. This version only work with .NET 6.0.
You can check existing .net versions right here
So, you need to specify the version. The version for .NET 4.7.2 is the 3.1.31.
Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 3.1.31
Nuget Sqlite package info here

Update version of package that's internally referenced from another package

My project uses .NET Standard Library version 2.1.0. One of the packages that it references is System.Net.WebSockets.Client version 4.0.2.0. This package in its turn has a dependency on System.Security.Cryptography.X509Certificates version 4.1.0. As a result, when I restore before build, this particular version gets downloaded. The issue is version 4.1.0 of System.Security.Cryptography.X509Certificates has a known vulnerability and should get updated to 4.1.2 which has the vulnerability fixed.
I am not sure how to update the version of a package that is being internally referenced from another package which itself is part of the .NET Standard Library.
I am getting flagged in my build for using the non-compliant version of the X509Cerificates package. Any pointers in this regard would be much appreciated.
Thanks.

How do I call stored procedures using Entity Framework Core in a .NET Core 3.1 console application?

I have a C# .NET Core 3.1 console application. I need to query a SQL database via stored procedures for data retrieval.
I've been trying to use NuGet to install Microsoft.EntityFrameworkCore packages into the projects.
I get errors saying that Entity Framework Core 5.0 is not compatible with .Net Core 3.1. I've tried earlier versions of Entity Framework Core, but I still get compatibility errors.
Should I be trying to use Entity Framework Core with .NET Core? Is there a way around these compatibility issues?
How do I call SQL stored procedures from EF Core?
Here are the errors I'm seeing when I try to add EntityFrameworkCore.SQL package to my solution via NuGet:
Error Package restore failed. Rolling back package changes for 'Foo.WebAPI'.
Error NU1202 Package Microsoft.Extensions.DependencyInjection 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.DependencyInjection 5.0.0 does not support any target frameworks.
Error NU1202 Package Microsoft.IdentityModel.Tokens 5.6.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.IdentityModel.Tokens 5.6.0 does not support any target frameworks.
Error NU1202 Package System.Net.NameResolution 4.3.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package System.Net.NameResolution 4.3.0 supports: - monoandroid10 (MonoAndroid,Version=v1.0) - monotouch10 (MonoTouch,Version=v1.0) - xamarinios10 (Xamarin.iOS,Version=v1.0) - xamarinmac20 (Xamarin.Mac,Version=v2.0) - xamarintvos10 (Xamarin.TVOS,Version=v1.0) - xamarinwatchos10 (Xamarin.WatchOS,Version=v1.0)
Hopefully you were able to get around the install issues you were having with .net core 3.1->5.0 upgrade. One approach there might be to just start over with a new .net core console app targeted to core 5.0 and move all your buisness logic, etc into the new console app. If you did get through the upgrade issues, here's an answer to your question above.
var user = "johndoe";
var blogs = context.Blogs
.FromSqlRaw("EXECUTE dbo.GetMostPopularBlogsForUser {0}", user)
.ToList();
from Microsoft Docs "Raw Queries" https://learn.microsoft.com/en-us/ef/core/querying/raw-sql
Personally I try to avoic using SP's in code first EF like the plauge, but there are rare occasions where LINQ and EF cant handle the job and you have to goto SP's.

Azure Devops - Compatibility problems moving from .NET Core 3.1 to .NET 5 at Nuget Package

I have a .NET Core solution which was running well using .NET Core 3.1 using a Pipeline on Azure Devops. Everything was working fine on the Pipeline.
After moving from .NET Core 3.1 to .NET 5.0, I started to have some strange troubles running the pipeline, specifically with Nuget packages.
I can build with no problems, but when it starts to pack using Nuget Package, I've got this error:
[error] The nuget command failed with exit code(1)
NU1202: Package Microsoft.EntityFrameworkCore 5.0.0 is not compatible with net50 (.NETFramework,Version=v5.0). Package Microsoft.EntityFrameworkCore 5.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1)
Some weird fact is that this solution is running fine at the local machine.
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.8.8.9</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
I already tried to change the OS on the Build, but I've got this error:
The current available version of MSBuild is 16.7.0.37604. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
Does someone have an idea?
Package Microsoft.EntityFrameworkCore.Relational 5.0.0 supports:
netstandard2.1 (.NETStandard,Version=v2.1)
This is because it was using an old version of Nuget. You can try to change it to 5.x and restore.
Here is a case with similar issue you can refer to.

Dotnet restore not working

dotnet Version: 1.1.0 (global.json)
NuGet Version : 4.4.1.4656
VS2017 v15.5.2 (as Administrator)
.NET Core 1.1
The solution I am trying to build
Update I:
I just changed the project to run under target framework .NET Core v2.0 & sdk version 2.1.3 and I only get these kind of errors:
Severity Code Description Project File Line Suppression State
Error NU1202 Package Microsoft.Extensions.FileProviders.Physical 1.1.0
is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0).
Package Microsoft.Extensions.FileProviders.Physical 1.1.0 does not
support any target
frameworks. AspNetCoreExample C:\Users\Admin\Source\Repos\Examples\src\AspNetCoreExample\AspNetCoreExample.csproj 1
Update II:
While the following solves the current issue, i am not sure if it solves the root cause for this issue.
Delete the global nuget.config file %AppData%/Nuget/Nuget.config.
I fixed this issue by doing the following:
I migrated the project to .net core 2.0 and changed the global.json to point to sdk 2.1.3.
Removed all references in AspNetCoreExample manually and added the latest version for all of them.
Issues with target framework 1.1
When doing a restore from the solution in VS 2017:
When doing the restore from cmd (dotnet restore)
Running dotnet restore in Package Manager Console
NuGet.targets(103,5): error : Access to the path 'System.Runtime.dll'
is denied
.NET Core SDKs installed:
.NET Host
Now when opening the solution I get:
Comparing the log entries you pasted to their AppVeyor build,
https://ci.appveyor.com/project/Autofac/examples
Your machine's NuGet configuration seems to be broken. Analyze that and fix the issues.
You should add this code to your .csproj file
<RuntimeFramework>2.0.3</RuntimeFramework>
This worked for me.