OLEDB Provider seemingly disappears during program execution

19 hours ago 1
ARTICLE AD BOX

First of all, I am working in a company that does not allow code sharing online, so I won't be able to post precise code examples, sorry about that.

I am having a really weird issue using an OleDbConnection in a C# program. The target framework is .NET Framework 4.7.2, and the "Prefer 32-bit" option in the .csproj does not have any impact on my problem; I already tried everything on that end. I am working with Visual Studio 2022 and Office 2016.

The issue I'm having is the classic error

'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

when trying to open a connection like this:

using (OleDbConnection connexionPv = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Temp\\doc.xlsx; Extended Properties='Excel 12.0';")) { connexionPv.Open(); }

The unexpected behavior here is the following: this precise code works perfectly when called in my program, until I call one of our .NET Standard 2.0 DLLs. After the call to that DLL, the code throws that exception.

The required provider is installed on my machine, and using the provided code snippet in a blank solution works just fine as well.

Example:

// This works just fine. using (OleDbConnection connection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Temp\\NeoPV_documentumExportTemp.xlsx; Extended Properties='Excel 12.0';")) { connection.Open(); } // My .NET Standard 2.0 external lib externalLib.DoWork();
// My .NET Standard 2.0 external lib externalLib.DoWork(); // This throws the exception. using (OleDbConnection connection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Temp\\NeoPV_documentumExportTemp.xlsx; Extended Properties='Excel 12.0';")) { connection.Open(); }

The external lib does not use OleDb in any way, nor does it open any Excel or Word files. It uses itext7 to generate PDFs, and a FileStream to read a XML, and that's pretty much it. But somehow, it impacts the retrieval of the provider after its call, which is very strange to me.

I don't know what important details I could share about the NuGets and external DLLs used in this context, but I can add them if asked.

Here are some leads I've already tried, to no avail (every one of them executed after the call to my external .NET Standard 2.0 app) :

Looking in the "Modules" window does not help, since it looks like the OleDb DLL is loaded within a COM context. Changing the OLE DB Version in the Connection String to 16.0 I also tried referencing directly all OleDb related DLLs in the project I've tried to execute the code in a new AppDomain, but it did not work either. AppDomain test = AppDomain.CreateDomain("test"); test.DoCallBack(() => { using (OleDbConnection connection = new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Temp\\NeoPV_documentumExportTemp.xlsx; Extended Properties='Excel 12.0';")) { connection.Open(); } });

Again, feel free to ask any important detail I could have missed, since I cannot post precise stuff on the external lib.

Thanks for your help.

Read Entire Article