mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

NSString.ValueForKey() causes EntryPointNotFoundException on iOS Device (not on Sim) #597

Open tombly opened 6 years ago

tombly commented 6 years ago

Hello!

If I add the following code to a library:

var x = new NSString("hello");
x.ValueForKey(new NSString("length"));

I get an exception:

System.EntryPointNotFoundException: xamarin_IntPtr_objc_msgSend_IntPtr
  at (wrapper managed-to-native) ObjCRuntime.Messaging:xamarin_IntPtr_objc_msgSend_IntPtr (intptr,intptr,intptr)
  at Foundation.NSObject.ValueForKey (Foundation.NSString ) [0x00038] in <e0596b82250c450abdf075bc558add28>:0 
  at MyLibrary.MyClass.Connect () [0x00058] in <1767c184b0c0449da4b164fa6fcdbec3>:0

Is this a bug or expected behavior or user error?

Additional details: I'm using the Embeddinator 0.4 (built from GitHub) to convert a Xamarin.iOS Class Library (built using VS Mac) and using the resulting native library in a typical native iOS app compiled with Xcode. I've successfully embedded the .NET library into the native iOS app, made calls to the library, etc., so everything seems to be working fine, I just run into a problem when I add the two lines above.

The Embeddinator is really awesome, well done.

Thanks! -Tom B.

chamons commented 6 years ago

I can confirm this works in the simulator and fails on device. Looking into the details now.

vlsim commented 6 years ago

Hi @chamons , Any updates on this issue? I ran into it when updating our mtouch and embeddinator:

System.TypeInitializationException: The type initializer for 'SomeLibraryClass' threw an exception. ---> System.EntryPointNotFoundException: xamarin_IntPtr_objc_msgSend_IntPtr at (wrapper managed-to-native) ObjCRuntime.Messaging.xamarin_IntPtr_objc_msgSend_IntPtr(intptr,intptr,intptr) at Foundation.NSObject.ValueForKey (Foundation.NSString key) [0x0001c] in /Xamarin/xamarin-macios/src/build/ios/native/Foundation/NSObject.g.cs:598

Was able to change the code from "ValueForKey" to "ObjectForKey" which seems to work in our case. The "ValueForKey" was most likely a result of previous version of tools generating this error at runtime: Received unhandled ObjectiveC exception: NSInvalidArgumentException *** -[NSDictionary objectForKey:]: method only defined for abstract class. Define -[__NSCFDictionary objectForKey:]!

Maybe you can point me in the right direction to investigate this?

rolfbjarne commented 6 years ago

xamarin_IntPtr_objc_msgSend_IntPtr is supposed to be in libxamarin.a, which is supposed to be linked into the resulting framework.

Can you attach a complete and verbose build log?