question

Hamid-5524 avatar image
0 Votes"
Hamid-5524 asked JamesVergara-0724 commented

System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient on Linux after migrating to .NET 6

Hello,

this week I have migrated project I'm currently working on from .NET 5 to .NET 6. I usually work on 2 OS systems (Win10 and Linux manjaro).

After migration project builds fine on both systems, but only on linux I get this exception:


 warn: Microsoft.EntityFrameworkCore.Model.Validation[10400]
       Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.
 Application startup exception: System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
    at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
    at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
    at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists()
    at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
    at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
    at OnlineSystem.RegistrationSystem.Framework.Data.DbContextsMigrator.MigrateDatabase(IServiceProvider serviceProvider, String[] dependentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Data/DbContextsMigrator.cs:line 31
    at OnlineSystem.RegistrationSystem.Framework.Environment.ApiStarter.EnsureDatabaseMigrations(IServiceProvider serviceProvider, String[] depdendentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Environment/ApiStarter.cs:line 48
    at OnlineSystem.RegistrationSystem.WebApi.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IHostApplicationLifetime appLifetime) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.WebApi/Startup.cs:line 251
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
    at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
    at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
    at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
    at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
    at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
 crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
       Application startup exception
       System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
          at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
          at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
          at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
          at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
          at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
          at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
          at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
          at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
          at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
          at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists()
          at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
          at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
          at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
          at OnlineSystem.RegistrationSystem.Framework.Data.DbContextsMigrator.MigrateDatabase(IServiceProvider serviceProvider, String[] dependentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Data/DbContextsMigrator.cs:line 31
          at OnlineSystem.RegistrationSystem.Framework.Environment.ApiStarter.EnsureDatabaseMigrations(IServiceProvider serviceProvider, String[] depdendentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Environment/ApiStarter.cs:line 48
          at OnlineSystem.RegistrationSystem.WebApi.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IHostApplicationLifetime appLifetime) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.WebApi/Startup.cs:line 251
          at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
          at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
          at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
          at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
          at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
          at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
          at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
          at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
 Unhandled exception. System.PlatformNotSupportedException: Strings.PlatformNotSupported_DataSqlClient
    at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerConnection.CreateDbConnection()
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
    at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
    at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
    at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists(Boolean retryOnNotExists)
    at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.Exists()
    at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
    at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
    at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
    at OnlineSystem.RegistrationSystem.Framework.Data.DbContextsMigrator.MigrateDatabase(IServiceProvider serviceProvider, String[] dependentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Data/DbContextsMigrator.cs:line 31
    at OnlineSystem.RegistrationSystem.Framework.Environment.ApiStarter.EnsureDatabaseMigrations(IServiceProvider serviceProvider, String[] depdendentAssemblies) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.Framework/Environment/ApiStarter.cs:line 48
    at OnlineSystem.RegistrationSystem.WebApi.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IHostApplicationLifetime appLifetime) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.WebApi/Startup.cs:line 251
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
    at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
    at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
    at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
    at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
    at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
    at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
    at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
    at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String startupMessage)
    at Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token)
    at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
    at OnlineSystem.RegistrationSystem.WebApi.Program.Main(String[] args) in /<ProjectPath>/src/OnlineSystem.RegistrationSystem.WebApi/Program.cs:line 27

The exceptions happens in:
class DbContextsMigrator
{
public void MigrateDatabase(IServiceProvider serviceProvider, string[] dependentAssemblies)
{
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
if (dependentAssemblies == null)
throw new ArgumentNullException(nameof(dependentAssemblies));

             Assembly[] assemblies = LoadAssemblies(dependentAssemblies);
    
             Type[] dbContextTypes = assemblies.SelectMany(a => a.GetExportedTypes())
                 .Where(t => typeof(DbContext).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract)
                 .ToArray();
    
             foreach (Type eachDbContextType in dbContextTypes)
             {
                 var genericDbContextOptionsType = typeof(DbContextOptions<>).MakeGenericType(eachDbContextType);
    
                 object dbContextOptionsInstance = serviceProvider.GetService(genericDbContextOptionsType);
    
                 using (DbContext contextInstance = (DbContext) Activator.CreateInstance(eachDbContextType, dbContextOptionsInstance))
                 {
                     contextInstance.Database.Migrate();
                 }
             }
         }
    
         private Assembly[] LoadAssemblies(string[] dependentAssemblies)
         {
             var assemblies = new Assembly[dependentAssemblies.Length];
    
             for (int i = 0; i < dependentAssemblies.Length; i++)
             {
                 assemblies[i] = Assembly.Load(dependentAssemblies[i]);
             }
    
             return assemblies;
         }
   }

I have tried to revert nuget packages to their previous versions (no luck), use previous .net version is impossible now, as .net 6 is directly updated from manjaro's package manager. I tried to add/remove packages from what I found on the internet as solutions but exception still persists.

The weirdest part is, that if I run the same code/same nuget packages on win10/visual studio 19 it runs fine.

Can anyone help me with this?

sql-server-generaldotnet-csharpdotnet-aspnet-core-webapi
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I found the solution using the --os and --arch flags

 dotnet run --arch x64 --os linux
1 Vote 1 ·

Which version of Entity Framework Core are you on?

0 Votes 0 ·

All EntityFramework packages are at version 6.0.0

0 Votes 0 ·

Hi @Hamid-5524,

The PlatformNotSupportedException exception is thrown when a feature does not run on a particular platform.

You could try to check the installed packages and try to update them to the latest version, and check if there is any special package for the Linux Manjaro platform. If still not working, means that it not support the Linux Manjaro platform. Then, you can submit this problem to Asp.net core.

Best regards,
Dillion

0 Votes 0 ·

I already tried downgrading the package (SqlServer) down to 5.0.12 and 5.0.11 (didn't work) then I tried to pull clean version from git (version which works on windows) and the exception still persists.

I will try to open problem on that github page.

0 Votes 0 ·

Hello, did you manage to solve this?, I have the same problem. I also use manjaro

0 Votes 0 ·

0 Answers