Skip to content

Null reference on Microsoft.Data.SqlClient.SqlClientFactory.Instance #1424

Closed

Description

@jogibear9988

Describe the bug

I try to register SqlClient as a Dataprovider in my NetCore6 Application, but the Field Microsoft.Data.SqlClient.SqlClientFactory.Instance is null. It has worked before, but does not any more, since I implemented my own AssemblyResolver.

Where in the Code is the instance Assigned, so I can debug whats wrong. I get no exception when Loading the DLL, or before accessing that static field (I've enabled break on all exceptions in Visual Studio)

To reproduce

At the moment it will be hard to create a reproducible scenario. I'd firstly try to debug myself, if someone explains to me where the Field is assigned.

Expected behavior

A clear and concise description of what you expected to happen.

Further technical details

Microsoft.Data.SqlClient version: 4.0.0
.NET target: NET6.0
SQL Server version: doesn't matter
Operating system: Windows 10

Activity

  1. jogibear9988 commented on Dec 7, 2021

    @jogibear9988
    Author

    Okay, if I look here:

    public static readonly SqlClientFactory Instance = new SqlClientFactory();

    the Factory is assigned immediately, but if I open the DLL on my system in ILSpy it looks like this:

    image

  2. jogibear9988 commented on Dec 7, 2021

    @jogibear9988
    Author

    Ahhh....

    now I found the dll in
    runtimes\win\lib\netcoreapp3.1

  3. jogibear9988 commented on Dec 7, 2021

    @jogibear9988
    Author

    so I load the wrong one.

  4. gumbarros commented on Sep 15, 2022

    @gumbarros

    I also having the same problem on Pop!_OS 22.10

  5. kvisscher commented on Oct 12, 2022

    @kvisscher

    @gumbarros I'm having the same issue on Pop 22.04. Did you manage to solve your issue?

  6. gumbarros commented on Oct 12, 2022

    @gumbarros

    @gumbarros I'm having the same issue on Pop 22.04. Did you manage to solve your issue?

    No, but our customer updated to a more recent server and now is working. But in the old server still not working.

    The upgrade was from WinServer 2012 to 2019 I think.

  7. kvisscher commented on Oct 12, 2022

    @kvisscher

    @gumbarros thanks for the quick reply!

    I actually just found another related issue that exactly matched my issue: #1643. Hopefully it can help someone in the future.

    I installed dotnet via the apt repository, but for some reason, this didn't work. I reinstalled with the install script: https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install and everything is up and running again.

  8. gumbarros commented on Oct 12, 2022

    @gumbarros

    @gumbarros thanks for the quick reply!

    I actually just found another related issue that exactly matched my issue: #1643. Hopefully it can help someone in the future.

    I installed dotnet via the apt repository, but for some reason, this didn't work. I reinstalled with the install script: https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install and everything is up and running again.

    Sorry I saw the notification on my phone and confuded with this issue microsoft/azuredatastudio#11249 (comment).

    To solve #1424 I manually installed .NET in my OS (without apt or snap)

  9. xiaoyuvax commented on Jun 16, 2023

    @xiaoyuvax

    I have almost the same problem! now on net7.0.
    I found the problem only occurs if use own AssemblyResolver!! with the exception:

    System.InvalidOperationException:“The requested .NET Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.”

    In my project, i met the same issue when System.Data.SqlClient is only loaded by my own plugin assembly loader, where the AppDomain.CurrentDomain.AssemblyResolve delegate is used to resolve assemblies.

    If i reference System.Data.SqlClien directly as nuget package in my entry assembly, it works well. but not possible as in plugin.
    I think there's something wrong in underlying assembly resolving process, when use own assembly resolver.

    I replaced System.Data.SqlClient with Microsoft.Data.SqlClient, it's the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions