Oracle blocks NET6 migration - Detected package version outside of dependency constraint - c#

I am currently migrating our main NET Core 3.1 app to NET 6. Our database access layer is encapsulated into a class library using EF Core 3.1 that also needs migrating to a newer version. In that lib, there is logic to access 2 databases, Azure Sql und Oracle Sql.
The Oracle.EntityFrameworkCore nuget package is not yet available for NET6.
dotnet restore gives the following warning:
warning NU1608: Detected package version outside of dependency constraint: Oracle.EntityFrameworkCore 5.21.4 requires Microsoft.EntityFrameworkCore.Relational (>= 5.0.9 && < 6.0.0) but version Microsoft.EntityFrameworkCore.Relational 6.0.0 was resolved.
Running a query against Oracle throws a TypeLoadException
Unhandled exception. System.TypeLoadException: Method 'AppendIdentityWhereCondition' in type 'Oracle.EntityFrameworkCore.Update.Internal.OracleUpdateSqlGenerator' from assembly 'Oracle.EntityFrameworkCore, Version=5.0.21.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.
at Microsoft.Extensions.DependencyInjection.OracleServiceCollectionExtensions.<>c.<AddEntityFrameworkOracle>b__0_4(ServiceCollectionMap b)
at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.TryAddProviderSpecificServices(Action`1 serviceMap)
at Microsoft.Extensions.DependencyInjection.OracleServiceCollectionExtensions.AddEntityFrameworkOracle(IServiceCollection serviceCollection)
at Oracle.EntityFrameworkCore.Infrastructure.Internal.OracleOptionsExtension.ApplyServices(IServiceCollection services)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<GetOrAdd>g__BuildServiceProvider|4_0(IDbContextOptions options, ConcurrentDictionary`2 configurations)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd[TArg](TKey key, Func`3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
at OracleLib.MyDbContext..ctor(DbContextOptions`1 options)
at App.Program.Main(String[] args) in C:\Users\me\app\Program.cs:line 39
at App.Program.<Main>(String[] args)
I then tried splitting the Azure Sql part and Oracle Sql part, with the latter targeting only NET5. I then dotnet pack'ed both libs and included them in an NET6 app. But again, I am getting the above warning and typeload exception.
Oracle effectively keeps me from migrating to NET6. Is there any way I can tell the oracle lib to use its own lower version of Microsoft.EntityFrameworkCore.Relational and call it a day?

Related

Method not found: 'Microsoft.Extensions.DependencyInjection.ServiceProvider'

I have developed a simple console application in .NET6 with target Platform x86 which contains 1 project only with the following packages:
Microsoft.AspNetCore.SignalR.Client (6.0.5)
Microsoft.AspNetCore.SignalR.Common(6.0.5)
Microsoft.AspNetCore.SignalR.Core(1.1.0)
System.IO.Ports (6.0.0)
Also it contains an API to communicate with a Dispenser.
This console application send and recieve data with main software throught SignalR and send and recieve data with Dispenser throught API.
I don't use any dependency injection and the Dispenser response when I try to initialize it is the next one:
Método no encontrado: 'Microsoft.Extensions.DependencyInjection.ServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
Any idea why the response is that?
Microsoft.AspNetCore.SignalR.Core seems to be a legacy package (last updated in 2018) and was build against Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0), while Microsoft.AspNetCore.SignalR.Client is transitively using Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0) so the later version should be resolved during build. And it definitely has some breaking changes (like removal or signature changes of ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection) method)
Try removing Microsoft.AspNetCore.SignalR.Core package, Microsoft.AspNetCore.SignalR.Client should be sufficient enough to connect to the SingnalR server.

NSWAG update to .NET6 - .NETPlatform,Version=v6.0 not found

I've updated all projects in my solution to use .net6, and have updated nswag json file to runtime to Net60.
I have .net 6.0.100 installed.
Here is the build output
$ dotnet build Solution.sln
Microsoft (R) Build Engine ersion 17.0.0+c9eb9dd64 for .NET
Restored C:\src\...\Client.csproj (in 455 ms).
NSwag command line tool for .NET Core Net60, toolchain v13.15.10.0 (NJsonSchema v10.6.10.0 (Newtonsoft.Json v13.0.0.0))
NSwag bin directory: C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\tools\Net60
Executing file 'nswag.json' with variables 'Configuration=Debug'...
C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\.Client.csproj]
System.InvalidOperationException: Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project.If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
at NSwag.Commands.Generation.AspNetCore.ProjectMetadata.GetProjectMetadata(String file, String buildExtensionsDir, String framework, String configuration, String runtime, Boolean noBuild, String outputPath, IConsoleHost console) in /_/src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs:line 152
C:\src\....Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
C:\Program Files\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETPlatform,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\src\API.csproj] [C:\src\...\Client.csproj]
C:\src\...\.Client.csproj(15,5): error MSB3073: The command "dotnet "C:\Users\...\.nuget\packages\nswag.msbuild\13.15.10\build\../tools/Net60/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
I did find a workaround - it gets me past the problem.
In the nswag.json file, it fails when I reference the project in the project element of
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project" "../relative/path/to/.csproj",
"assemblyPaths": [
"../../bin/dotnet6.0/MyAPI.dll"
]
}
}
So remove project.
And reference the output DLL from your project in the assemblyPaths[] array.
It builds successfully & the client is regenerated.

UseMySql in Pomelo throwing exception

So I have seen the strangest behavior with the Pomelo package for .NET Core.
var optionsBuilder = new DbContextOptionsBuilder<AssessmentContext>();
var cn = String.Format(config["ConnectionStrings:AwsConnection"], config["Aws:MySQLPassword"]);
optionsBuilder.UseMySql(cn);
db = new AssessmentContext(optionsBuilder.Options);
I've had the above code in unit tests to set up connect to a MySQL database in AWS. This has worked just fine for about a week now. However, starting today, when it gets to optionsBuilder.UseMySql(cn); now I'm getting an exception.
Assessment.Tests.Data.Contexts.AssessmentContextTests.ConnectToMySQL:
Outcome: Failed
Error Message:
Class Initialization method Assessment.Tests.Data.Contexts.AssessmentContextTests.Initialize threw exception. System.TypeLoadException: System.TypeLoadException: Could not load type 'MySql.Data.MySqlClient.MySqlConnectionStringBuilder' from assembly 'MySqlConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d33d3e53aa5f8c92'..
Stack Trace:
at Microsoft.EntityFrameworkCore.MySqlDbContextOptionsExtensions.UseMySql(DbContextOptionsBuilder optionsBuilder, String connectionString, Action`1 mySqlOptionsAction)
at Microsoft.EntityFrameworkCore.MySqlDbContextOptionsExtensions.UseMySql[TContext](DbContextOptionsBuilder`1 optionsBuilder, String connectionString, Action`1 mySqlOptionsAction)
at Assessment.Tests.Data.Contexts.AssessmentContextTests.Initialize(TestContext context) in
This has been working fine. I haven't updated any libraries, but it's failing and I'm unable to connect. Any thoughts? I'm using .NET Core 3.1, and pomelo version 3.0.1.
It's a version mismatch. MySqlConnector changed its namespace in version 1.0.0. Since this is a breaking change and Pomelo is SemVer2 compliant, Pomelo is still using MySqlConnector < 1.0.0 (currently 0.69.9).
Later versions of Pomelo (e.g. the current version 3.2.2) explicitly restrict the MySqlConnector version to below 1.0.0, so that using a MySqlConnection version >= 1.0.0 would lead to a compile time error instead of a runtime error.
So to fix the issue, use the latest version of MySqlConnector below 1.0.0.
On a side note, you should consider using EF Core 3.1.8 and Pomelo 3.2.2. There have been many bugfixes for Pomelo since version 3.0.1.

Xamarin.Firebase.Common not compatible with Xamarin.Firebase.Auth

I'm trying to install 'Xamarin.Firebase.Storage.42.1021.1' so I can upload photos to my firebase database
I'm targeting 'MonoAndroid, Version=v7.1'
However, when I try to install the package I get the following
Unable to find a version of 'Xamarin.Firebase.Common' that is compatible with 'Xamarin.Firebase.Auth 42.1024.0-beta1 constraint: Xamarin.Firebase.Common (= 42.1024.0-beta1)', 'Xamarin.Firebase.Storage 42.1021.1 constraint: Xamarin.Firebase.Common (= 42.1021.1)'.
Is there a quick fix without breaking my project?
You may checked the Dependencies of Xamarin.Firebase.Storage and Xamarin.Firebase.Auth.
According to your error message, you've installed the Xamarin.Firebase.Auth 42.1024.0-beta1 package, which needs dependency Xamarin.Firebase.Common (= 42.1024.0-beta1).
Try to downgrade your Xamarin.Firebase.Auth package to version 42.1021.1.

EF 6 with a dnx project

I have a new ASP.net 5 dnx class library I am using for entity framework. I need to target EF 6 because some features I need are not in EF 7.
First the EF tools (like enable-migration) were not there. I added an old style class library and installed EF 6 and now the commands are there.
When I run enable migrations I get this error:
PM> Enable-Migrations
Exception calling "SetData" with "2" argument(s): "Type
'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject'
in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation,
Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is
not marked as serializable." At
D:\Projects\Rebus\FMS\Code\Current\FMSSupport\FMSSupport\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720
char:5
+ $domain.SetData('startUpProject', $startUpProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException System.NullReferenceException: Object reference not set to an instance
of an object. at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project
project, Int32 shellVersion) at
System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project
project) at
System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String
configurationTypeName, Boolean useContextWorkingDirectory) at
System.Data.Entity.Migrations.EnableMigrationsCommand.FindContextToEnable(String
contextTypeName) at
System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
at
System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action
command) Object reference not set to an instance of an object.
I have tried different options for enable-migration such as specifying a startup project or the contextTypeName.
Any ideas?
Following this recommendation, EF6 data projects should use the existing .NET Framework class library csproj type.
Even after following the recommendations, I was still getting the same error. Unloading your ASP.NET Core project(s) and then invoking the Enable-Migrations command on the appropriate csproj should allow the command to execute. You can unload a project by right-clicking on the .NET Core project and choosing the 'Unload Project' option. It should also be noted that the Package Manager Console window has a 'Default project:' drop-down selection. You should choose the project with your DbContext.
It's because ASP.NET Core introduced a new project type/configuration system (see package.config vs project.json) and the old EF tools don't know how to work with the newer system (project.json). It would probably be easiest to create a new project and port your code into it if you want to go back to EF6.
Interestingly (well, disappointingly actually) they're backtracking on project.json see:
http://xoofx.com/blog/2016/05/11/goodbye-project-json/
I had the same issue. Just setting the start project from ASP.NET Core to my .NET Framework Lib does the trick for me =) Now i can do EF6 migrations as usual "Add-Migration" command...
P.S. Sorry for my eng.

Categories

Resources