[CSHARP-1875] System.DllNotFoundException: ntdll.dll Created: 27/Dec/16  Updated: 22/May/17  Resolved: 30/Mar/17

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 2.4
Fix Version/s: 2.4.4

Type: Bug Priority: Major - P3
Reporter: Andreas Vilinski Assignee: Robert Stam
Resolution: Done Votes: 6
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

System.DllNotFoundException: ntdll.dll



 Description   

Whats going on here? Can't connect. Is mono supported

Mono under MacOS

mono --version
 
Mono JIT compiler version 4.6.1 (mono-4.6.0-branch-c8sr0/abb06f1 Fri Sep 23 19:24:23 EDT 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug
	LLVM:          yes(3.6.0svn-mono-master/8b1520c)
	GC:            sgen

System.TypeInitializationException: The type initializer for 'Db.Mongo' threw an exception. ---> System.TypeInitializationException: The type initializer for '<StartupCode$Kraken>.$Db.Mongo' threw an exception. ---> System.DllNotFoundException: ntdll.dll
  at (wrapper managed-to-native) Interop+NtDll:RtlGetVersion (Interop/NtDll/RTL_OSVERSIONINFOEX&)
  at Interop+NtDll.RtlGetVersion () [0x0001a] in <dd91439f3167478ebd2cbf9c036a1395>:0 
  at System.Runtime.InteropServices.RuntimeInformation.get_OSDescription () [0x00007] in <dd91439f3167478ebd2cbf9c036a1395>:0 
  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument () [0x00042] in <44d1ee4d649846bda18b2609a70d66b9>:0 
  at System.Lazy`1[T].CreateValue () [0x00075] in <dca3b561b8ad4f9fb10141d81b39ff45>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
  at Db.Mongo..cctor () [0x00000] in <5862ad762f76149ea745038376ad6258>:0 



 Comments   
Comment by Robert Stam [ 30/Mar/17 ]

We've merged in the pull request (with slight refactoring).

Note that while this removes one obstacle to using the driver on Mono it does not imply official support for running on Mono. That's a separate question.

Comment by Githook User [ 29/Mar/17 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1875: Code review refactoring.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/8a096206ca3e7fb9b0c0f7b5aaf6e293c7c0b4dc

Comment by Githook User [ 29/Mar/17 ]

Author:

{u'username': u'MarLoe', u'name': u'Martin Lobger', u'email': u'martin@lobger.com'}

Message: CSHARP-1875: Steer clear of code that needs ntdll.dll

Removing left behind obsolete line.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5a3ae44813e7e0bae9887fe26ea0f63365240394

Comment by Githook User [ 29/Mar/17 ]

Author:

{u'username': u'MarLoe', u'name': u'Martin Lobger', u'email': u'martin@lobger.com'}

Message: CSHARP-1875: Steer clear of code that needs ntdll.dll

And making sure it compile/works on .NET Standard / Core as well
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/1c39aaeedeb61bc9601a344b9461e5e6d27fad8e

Comment by Githook User [ 29/Mar/17 ]

Author:

{u'username': u'MarLoe', u'name': u'Martin Lobger', u'email': u'martin@lobger.com'}

Message: CSHARP-1875: Steer clear of code that needs ntdll.dll
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/bf6990200d27b153cf273fb1d04272e6c4bf7658

Comment by Martin Lobger [ 11/Jan/17 ]

@rstam

I have created a pull request that solves this issue:
https://github.com/mongodb/mongo-csharp-driver/pull/265

Comment by Andreas Vilinski [ 10/Jan/17 ]

@RobertStam

  • My build process and execution runs under mono/linux
  • It seems really that MongoDB.Driver.Core references System.Runtime.InteropServices.RuntimeInformation,
  • Paket downloads it from nuget System.Runtime.InteropServices.RuntimeInformation (4.3), the binary differs from what I have actually in GAC.
  • It works fine if I delete the dll manually
  • As a workaround one can also stick to MongoDB.Driver 2.3, which didn't have this problem because it didn't referenced it.

regardless of that, very sorry to hear you have stopped the mono support, because .NET Core is still very unstable and not yet adopted by other libs.

Comment by Martin Lobger [ 10/Jan/17 ]

I experience this issue as well using Visual Studio for macOS. It used to work with 2.3.0. The new version 2.4.1 does not fix the problem either.

{System.DllNotFoundException: ntdll.dll
  at (wrapper managed-to-native) Interop+NtDll:RtlGetVersion (Interop/NtDll/RTL_OSVERSIONINFOEX&)
  at Interop+NtDll.RtlGetVersion () [0x0001a] in <dd91439f3167478ebd2cbf9c036a1395>:0 
  at System.Runtime.InteropServices.RuntimeInformation.get_OSDescription () [0x00007] in <dd91439f3167478ebd2cbf9c036a1395>:0 
  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument () [0x00042] in <2c531fdd26874b5eb450bd126d409101>:0 
  at System.Lazy`1[T].CreateValue () [0x00075] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/Lazy.cs:437 }
	Data: {System.Collections.ListDictionaryInternal}
	HResult: -2146233052
	HelpLink: (null)
	InnerException: (null)
	Message (System.Exception): "ntdll.dll"
	Message (System.TypeLoadException): "ntdll.dll"
	Source: (null)
	StackTrace: "  at (wrapper managed-to-native) Interop+NtDll:RtlGetVersion (Interop/NtDll/RTL_OSVERSIONINFOEX&)\n  at Interop+NtDll.RtlGetVersion () [0x0001a] in <dd91439f3167478ebd2cbf9c036a1395>:0 \n  at System.Runtime.InteropServices.RuntimeInformation.get_OSDescription () [0x00007] in <dd91439f3167478ebd2cbf9c036a1395>:0 \n  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateOSDocument () [0x00042] in <2c531fdd26874b5eb450bd126d409101>:0 \n  at System.Lazy`1[T].CreateValue () [0x00075] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/Lazy.cs:437 "
	TargetSite: (null)
	TypeName: ""
	Static members: 
	Non-public members: 

Comment by Ron Elliott [X] [ 07/Jan/17 ]

Looks like it was installed with the mono package I downloaded from http://www.mono-project.com/download/, specifically https://download.mono-project.com/archive/4.6.2/macos-10-universal/MonoFramework-MDK-4.6.2.16.macos10.xamarin.universal.pkg I just tried a fresh install with the same issue. However since you no longer support mono I guess the issue is resolved.

Comment by Robert Stam [ 03/Jan/17 ]

We used to officially support Mono for the 1.x versions of the driver, but as of the 2.x versions of the driver we no longer officially support Mono. We also no longer test against Mono.

We actually don't reference ntdll.dll at all. We do however reference System.Runtime.InteropServices.RuntimeInformation.dll, which according to the stack trace you provided seems to be calling into ntdll.dll.

Where did you get your copy of System.Runtime.InteropServices.RuntimeInformation.dll? It looks like you might be trying to use the Windows version of that DLL on a non-Windows machine.

Comment by Ron Elliott [X] [ 01/Jan/17 ]

Same issue here, I tried various DLL mappings for Mongo.Engine.Core.dll and Mongo.Engine.dll and none seemed to work.

Generated at Wed Feb 07 21:40:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.