-
-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoke-DbaQuery error: An attempt was made to load a program with an incorrect format. (0x8007000B) #9190
Comments
I've seen this issue pop up and I don't know how to fix it :/ DLLs aren't my forte but i'm pretty sure this is an issue with SqlClient SNI as that has x86 in the filename. |
looks like this provides some insight dotnet/SqlClient#645 |
I've spent a couple of hours digging through this, and I feel like I know less now than when I started. :-/ I believe that what I read was that the transition from System.Data.SqlClient->Microsoft.Data.SqlClient, SNI was moved from being a stand-alone DLL ("sni.dll") to being included within Sql client ("Microsoft.Data.SqlClient.SNI.dll") . Also, from the function names in the stack trace ("UnmanagedIsTotkenRestricted"), I get the feeling that we are calling out of .NET and into old-school Windows. If you look at the code for SNINativeWrapper, it's definitely an extern/DllImport. That seems to make things more confusing. But, a few things: the "SNI.dll" and "SNI.X64.dll" files are exactly the same size, implying they are really two copies of the same file. If the x86 code is naively looking for "SNI.dll", expecting it to be x86, that's probably a problem. I did rename that SNI.dll file out of the way and retested, with no observable difference-it still throws in Microsoft.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(). Second thing is that I see that there is a "sni.dll" file in the PowerShell (7) files. When we looked at this issue last year, you didn't seem to see the problem in your 32 bit test environment. If that is so, is there some way I can compare what I have in my environment with the test environment? There has to be some kind of difference, maybe in the way or order in which DLLs are found on a Windows computer? The third thing is that I now have a better repro script. It's built from the guts of Connect-DbaInstance, but it relies on the DLLs loaded by Import-Module dbatools. The new repro script has the same failure and the stack trace is the same.
|
One thing to consider @ashdar if you want to fully convert to PowerShell 7.4 x64 is isolating your need for the x86 via The library version we have from Microsoft is all Microsoft-owned code. The repo script you provided is what you can provide to their repository for issue tracking; it is an upstream issue in that regard. At this point all we can do is see if they want to fix it or not. I do believe your best option is to move that data interaction required with those x86 drivers to an isolated process. |
I am not sure that going from 32 to 64 will help my process performance, but I am sure that going from PowerShell 5.1 to PowerShell 7 will help and I can't get to 7 without doing something about my 32 bit problem. Are you thinking of something like the PSSession scheme mentioned here? Or something else? Can you point me to the correct repository to file an issue? Microsoft.SqlServer.Management or Microsoft.Data.SqlClient? |
Same repo Chrissy linked to in her comment #9190 (comment) |
Hi.
I believe that we can fix the problem described by this ticket with the following:
I have proven that, if I copy the Microsoft.Data.SqlClient.DLL, Microsoft.Identity.Client.dll and x64 version of the Microsoft.Data.SqlClient.SNI.DLL file into a directory, I can import-module 'Microsoft.Data.SqlClient.DLL' and everything works as I expect. (FWIW, this combination of DLLS, with the x86 version of SNI.DLL and the IL versions of the other two DLLs, fails in a x64 PowerShell process.) I have a first-pass at a fix of the dbatools.library code in my forked copy of the dbatools.library project. I can't test it properly because I'm having a lot of trouble getting the dbatools.library build scripts to work as I would expect on my local computer and I'm not familiar with how the Workflow stuff works, especially for a forked project, so I'm roadblocked.. So, two questions:
|
Closing this ticket in favor of the ticket over in the dbatools.library project. |
thank you! i'll take a look when my brain is working ..and update wh ile im at it. |
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Steps to Reproduce
Please confirm that you are running the most recent version of dbatools
I am running 2.1.5 and I took particular care to remove any old versions of dbatools that were on my systems.
Other details or mentions
The problem does not occur with Windows PowerShell 5.1 x86 or 86, nor with PowerShell 7.4 x64. I am stuck using 32 bit consoles because my client has important data in an antique format with only 32 bit OLEDB drivers.
This problem keeps me from fully moving to PowerShell 7.4. I have to maintain twice as many PowerShell environments as I would otherwise need to do.
I use PSFramework logging with a SQL Server target, and this shows up there too because PSFramework uses dbatools for SQL access. IOW, I can't use PSFramework logging in a PowerShell 7.4 x86 process.
I can reproduce the same problem on two different workstations, one is Windows 10 and the other is Windows 11.
I can reproduce the problem when connecting to any SQL Server, the version doesn't seem to matter because we never get to actually connecting.
A year ago, I opened the same bug: #8638 It seemed to be fixed for the then-unreleased version 2.0. So, that bug was closed and I started waiting for the release. One thing led to another and I didn't get a chance to update my third-party modules until now, the end of the year, and I seem to have the same problem.
As far as .NET versions go, do I need to have exactly 4.6.2 or is 4.8.09037 good enough?
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
Name Value
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
SQL Server Edition and Build number
I can reproduce the problem when connecting to any SQL Server, the version doesn't seem to matter because we never get to actually connecting.
.NET Framework Version
output from first method (looks at get_FrameworkDescription()
.NET 8.0.0
2nd method (looks at the Registry)
PSChildName Version
Client 4.8.09037
Full 4.8.09037
Client 4.0.0.0
The text was updated successfully, but these errors were encountered: