Skip to content

NUnit has a P/Invoke whose native function doesn't exist on all platforms #3618

@rolfbjarne

Description

@rolfbjarne

Repro project: nunitlite-3.12.0-c582df3.zip

To reproduce, download and extract, and then execute msbuild /p:Platform=iPhone /r

This results in a few errors:

  Undefined symbols for architecture arm64:
    "_GetVersionEx", referenced from:
        wrapper_managed_to_native_NUnit_Framework_Internal_OSPlatform_GetVersionEx_NUnit_Framework_Internal_OSPlatform_OSVERSIONINFOEX_ in nunit.framework.dll.o
  ld: symbol(s) not found for architecture arm64

MTOUCH : error MT5210: Native linking failed, undefined symbol: _GetVersionEx. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. [/Users/rolf/Projects/nunitlite-3.12.0/nunitlite-3.12.0.csproj]

Full build log

This is the P/Invoke in question:

[DllImport("Kernel32.dll")]
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osvi);

This is clearly a Windows-only P/Invoke, since GetVersionEx is a Windows-only function.

For Xamarin.iOS apps it's highly recommended to not have P/Invokes to functions that don't exist on the platform, because otherwise we have to apply a workaround that has a performance impact on the application.

Would it be possible to rework this code somehow so that the NUnit assemblies that are used for Xamarin.iOS (and tvOS/watchOS) don't have this P/Invoke?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions