Error on System.MethodAccessException in 'Microsoft.Extensions.Logging.Configuration.LoggerProvider - c#

I use visual studio to create the new web project which is MVC in .net Framework 4.8 under .net core 2.2.
When I use nuget to get the Microsoft.EntityFrameworkCore.SqlServer
and start to run (debug), I got the below exception
System.MethodAccessException: 'Attempt by method 'Microsoft.Extensions.Logging.Configuration.LoggerProviderConfigurationFactory.GetConfiguration(System.Type)'
to access method 'Microsoft.Extensions.Logging.ProviderAliasUtilities.GetAlias(System.Type)' failed.'
My Project properties is only this
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
</ItemGroup>
</Project>
Can you help to solve this problem ?
Thank you

the solution was downloading the Microsoft.Extensions packages and updating the versions so it can be equivalents.
here were the main answer and the discussions:
I suspect the issue is due to mismatched package versions. You will
certainly need to update all EntityFrameworkCore packages to the same
version. I expect you will also need to pull in the latest 3.1
versions of Microsoft.Extensions packages, since the EF packages
depend on the 3.1 versions of these packages.
discussion

Related

Adding SpecFlow to existing .Net 5.0 project nets RhinoMocks version error

I am adding SpecFlow to a C# project that has target net5.0, I get an error while trying to install SpecFlow 3.9.74 that should have .net 5 support starting in version 3.5.5, As best as I can see it's a dependency that's having an issue.
Error:
Severity Code Description Project File Line Suppression State
Warning NU1701 Package 'RhinoMocks 3.6.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net5.0'. This package may not be fully compatible with your project. DSA.Automation.Core C:\Users\******Automation.Core.csproj 1
the csproj file has the following configs:
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Microsoft.Playwright" Version="1.25.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.25.0" />
<PackageReference Include="MongoDB.Driver" Version="2.17.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>

How to install entity framework core to asp.net core 3 project using visual studio code

I'm creating a new MVC application using visual studio code and I want to add entity framework core to my project. My application is using the latest .net core 3 but when I tried to install package Microsoft.EntityFrameworkCore.SqlServer its show an error like this
Unable to resolve 'Microsoft.EntityFrameworkCore.SqlServer (>= 3.0.0)' for '.NETCoreApp,Version=v3.0'
How can I solve this issue?
ASP.NET Core 3.0 removes some assemblies that were previously part of the Microsoft.AspNetCore.App package reference.
You should add the package references for removed assemblies.
In XML project file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UserSecretsId>My-secret</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
</ItemGroup>
</Project>
Take a look here.

Multi-targeting .net core 2.2 with .net 4.6.1

I had started on an application on gathering data from meteorological stations for some time now and to make it cross platform I used .net core 2.2 mvc along with some libraries.
Even though the data is saved in a mysql db, the client recently requested that selected meteo records from a list, to be saved in a local access db.
To achieve that I had to use the legit database provider from microsoft which in this case is EntityFrameworkCore.Jet.
I didn't know that there was a compatibility issue at first resulting in a
Could not load type 'System.Data.OleDb.OleDbConnection' from assembly 'System.Data,
in this part of the code:
var msAccessDb = _msAccessRepo.InitializeDatabaseContext(connectionString);
msAccessDb.Database.OpenConnection();
Now it comes to the point where I have to do some multi-targeting on my .csproj files. What kind of syntax do I have to write?
The first thing that I have to do is update the .csproj file like so:
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
But all my packages like automapper, Pomelo.EntityFrameworkCore.MySql, Entity Framework tools, NLog, compile under the netcoreapp2.2 framework. I get all sorts of errors mainly CS0234, and CS234 even with the Condition inside the Itemgroup xml part like so:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="EntityFrameworkCore.Jet" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="MySql.Data" Version="8.0.17" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.17" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
</ItemGroup>
Must I downgrade my app and change from .net core to .net framework? Or am I doing something wrong in my multi-targeting?
Thank you in advance for your help.
[EDIT]
Based on the answer below, my Project.Web.csproj file is the following:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<UserSecretsId>aspnet-myProject.Web-BBF62A3C-EE9E-4808-8924-F2BEA33CDBD6</UserSecretsId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
<PackageReference Include="EntityFrameworkCore.Jet" Version="2.2.0" />
<PackageReference Include="System.Data.OleDb" Version="4.6.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2'">
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="MySql.Data" Version="8.0.17" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.17" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2'">
<ProjectReference Include="..\myProject.DB\myProject.DB.csproj" />
<ProjectReference Include="..\myProject.Lib\myProject.Lib.csproj" />
<ProjectReference Include="..\myProject.LoggerService\myProject.LoggerService.csproj" />
</ItemGroup>
Of course it started giving me build errors because I had to apply conditions for the different frameworks they apply. Not that the separate libraries at the bottom, are .net core 2.2 projects only and they do not target any other framework. Originally I had removed the 'Condition' but the build errors such as the following persist (as many as 850 errors).
The type or namespace name 'UserManager<>' could not be found
I know that I understood something wrong, or maybe the .net core 2.2 is not supported to be multi-target with .net framework as old as 4.6.
Any further discussion to solve this, or prove that this multi-targeting will not work, wiil be appreciated.
You only have package references present for .NET Core. You should have an item group for each of the following if they apply:
.NET Framework assembly references (with a target framework Condition)
Nuget package references which are required for both target frameworks
Nuget package references which are needed for .NET Framework only (with a target framework Condition)
Nuget package references which are needed for .NET Core only (with a target framework Condition)
Additionally, System.Data.OleDb.OleDbConnection is not available natively in .NET Core. You will need to reference the System.Data.OleDb Nuget package.
Please try removing Condition=" '$(TargetFramework)' == 'netcoreapp2.2'" from the ItemGroup and add a reference to the package System.Data.OleDb.
If you need to take any references which are unique to a framework study my example below.
Here, for illustration, are the package references from a library of mine which targets .NET Standard 2.0 and .NET 4.8:
<ItemGroup Condition="'$(TargetFramework)'=='net48'">
<Reference Include="System.Configuration" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Extensions" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="System.Diagnostics.EventLog" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NodaTime" Version="2.4.7" />
</ItemGroup>
Note how I reference .NET Framework assemblies for framework net48, one Nuget package for netstandard2.0, and 3 Nuget packages for both targets.
I have yet to understand how multi-targeting in one project works, so what worked for me, was to create the specific (connection to access db) feature in a separate webapi project targeted in .net 4.8. The controller calls the web api method internally via httpClient and does the job.
I know that it is not ideal but for the time constraints that we have, it is a good solution.

.Net Core 2.0 Warning NU1603 during dotnet restore, problems with NuGet packages

(world!)
I am writing application APS .Net Core 2.0. In Test project after adding some NuGet packages to .csproj I meet some troubles. At the command dotnet restore an error pops up:
D:\01_Toci\100_GIT\Passenger\Passenger.Tests\Passenger.Tests.csproj :
warning NU1603: Castle.Core 4.0.0 depends on
System.ComponentModel.TypeConverter (>= 4.0.1) but
System.ComponentModel.TypeConverter 4.0.1 was not found. An
approximate best match of System.ComponentModel.TypeConverter 4.1.0
was resolved.
There is my .csproj code:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<AssemblyName>Passenger.Tests</AssemblyName>
<PackageId>Passenger.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Passenger.Core/Passenger.Core.csproj" />
<ProjectReference Include="../Passenger.Infrastructure/Passenger.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="FluentAssertions" Version="4.19.0" />
<PackageReference Include="Moq" Version="4.7.8" />
<PackageReference Include="dotnet-test-nunit" Version="3.4.0-beta-3" />
</ItemGroup>
</Project>
and project.assert.json (it's too long, so i decide to use pastebin)
I tried to change versions in the json file,
"System.ComponentModel.TypeConverter": "4.1.0",
and many other options, but nothing has been done...I was stuck. I got mixed up with these nuggets and I do not know how to get out of it.
Please help me.
This worked out for me, just add System.ComponentModel.TypeConverter as the newest version.
Managed to reproduce the same error without the packed added.
Remember to use the netcoreapp2.0 framework if you say you are using 2.0 instead of 1.1 as you were using for your test project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-*" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.*" />
<PackageReference Include="FluentAssertions" Version="4.19.0" />
<PackageReference Include="Moq" Version="4.7.8" />
<PackageReference Include="dotnet-test-nunit" Version="3.4.0-*" />
</ItemGroup>
</Project>

taghelpers intellisense not working in Preview5

I downloaded and installed latest .NET Core:
dotnet --version
1.0.0-preview5-004478
I also updated my AspNetCore project's package references:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.1.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="1.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" /> </ItemGroup>
It seems like tooling not working well yet for the latest versions. For example when I try to run dotnet ef it complains about missing project.json - which is depricated now.
I'm using Visual Studio 2017 Community RC and the integrated PM console can run add-migration, update-database,... so I don't care about missing dotnet ef support but if you had any idea of any workaround I would appreciate that becasue I also like to work with VS Code instead of the Studio.
My problem is now I try to build an ASP.Core MVC website with heavy usage of tag helpers. But the intellisense not working for that:
There is a known issue for VS2017 https://github.com/aspnet/Tooling/blob/master/known-issues-vs2017.md#tag-helpers-do-not-work and it links to a workaround "Install the Razor Language Service extension"
Update:
For the new release of Visual Studio 2017 Preview 15.3 (and from now on, i supposed) the razor language service is selected as a component inside the Visual Studio instalation process when you select the ASP.NET and web development workload
For Visual studio 17' you need to install this extension and it will work.
https://marketplace.visualstudio.com/items?itemName=ms-madsk.RazorLanguageServices
If you made the app with an MVC template, you don't have to install anything else from NuGet.
I fixed it in two steps.
1.Install Razor tool from package manager console. It is pre-release for now
Install-Package Microsoft.AspNetCore.Razor.Tools –Pre
Download and install Razor Language Services from marketplace. (Your visual studio instance should be closed)
After restart visual studio, intellisense and coloring should be working for tag helpers.

Categories

Resources