dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.
MIT License
860 stars 288 forks source link

Multi-targeting tests with app.config fails on .netcore (8) - #2932

Closed dfds-aslyn closed 3 weeks ago

dfds-aslyn commented 3 weeks ago

I have test projects targeting netframework 4.8 and net8.

As noted in the porting documentation, my test projects require an app.config to setup the provider for netframework 4.8; otherwise tests won't run in .netframework 4.8 with an exception that the provider has not been setup. .net8 runs fine, as I am using the [DbConfigurationType(typeof(MicrosoftSqlDbConfiguration))] attribute on dbcontexts.

The requirement of the app.config file causes the net8 tests to fail on the follow exception. How is multi-targeting supposed to work? I cannot find a way of conditionally using app.config files based on the target framework.

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
ConfigurationErrorsException: Unrecognized configuration section system.data. 

   at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
   at System.Data.Entity.Infrastructure.DependencyResolution.InternalConfiguration..ctor(ResolverChain appConfigChain, ResolverChain normalResolverChain, RootDependencyResolver rootResolver, AppConfigDependencyResolver appConfigResolver, Func`1 dispatchers)
   at System.Data.Entity.DbConfiguration..ctor()
   at System.Data.Entity.SqlServer.MicrosoftSqlDbConfiguration..ctor()
...
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

I am using Microsoft.EntityFramework.SqlServer 6.5.1. therefore Microsoft.Data.SqlClient >= 5.1.5

benrr101 commented 3 weeks ago

Hi @dfds-aslyn thanks for raising your issue. We need a bit more information to address this - can you provide us with a repro scenario and some more information on what environment you are using that causes this issue (what tests are you running, what test framework is running it, is this an ASP.NET app, etc)? We also want to make sure we route this issue correctly between the driver and entity framework, and this information can help us.

dfds-aslyn commented 3 weeks ago

I managed to use <AppConfig> in the csproj using a condition on net4 TF