Bug 59362 - DLLImport subframework HIServices from ApplicationServices
Summary: DLLImport subframework HIServices from ApplicationServices
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 3.6.0 (d15-3)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-09-08 21:53 UTC by Tim Uy
Modified: 2017-09-08 22:32 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Tim Uy 2017-09-08 21:53:20 UTC
I think this worked before Visual Studio for Mac. I am trying to access the HIServices framework which is a subframework of Application Services Framework (https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html). VSfM ends up adding '-framework HIServices' which does not work even from clang command line.

        public const string ApplicationServicesHIServicesFramework =
		[DllImport(ApplicationServicesHIServicesFramework, EntryPoint = "AXIsProcessTrustedWithOptions")]
		static extern sbyte _AXIsProcessTrustedWithOptions(IntPtr nsDictionaryRef);

		public static bool AXIsProcessTrustedWithOptions(NSDictionary dict)
			return _AXIsProcessTrustedWithOptions(dict.Handle) != 0;

If I try to clang -framework HIServices (vs a main framework like CoreText), I get

Tims-MacBook-Air:~ tim$ clang -framework HIServices
ld: framework not found HIServices

So I think the issue is the DllImport using the wrong '-framework' flag. I'm not sure what to actually do to import the subframework HIServices even from clang directly.

To recreate, just create a new Mac App in Visual Studio for Mac and try to add that DllImport. I do note that I do not see ObjCRuntime.Constants for HiServices.
Comment 1 Tim Uy 2017-09-08 22:03:33 UTC
I think the problem is the automatic adding of "-framework HIServices" which I cannot squelch. Maybe DllImport would do the right thing when running. Is that something new?
Comment 2 Tim Uy 2017-09-08 22:08:00 UTC
Maybe it sees the magic word "framework" in the dllimport and things that it should add -framework?
Comment 3 Tim Uy 2017-09-08 22:31:32 UTC
Some notes from Apple - https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/IncludingFrameworks.html - but no great insights. The question is how to DllImport subframeworks maybe without the "-framework HIServices" getting injected into clang. HIServices is in ApplicationServices. But I don't see a good way of mimicing #import <ApplicationServices/ApplicationServices.h> in XCode. 

This works in xcode, but I don't see any -framework calls.

#import <Cocoa/Cocoa.h>
#import <ApplicationServices/ApplicationServices.h>

int main(int argc, const char * argv[]) {

  bool isProcess = AXIsProcessTrusted();
  bool val = isProcess;
  return NSApplicationMain(argc, argv);
Comment 4 Tim Uy 2017-09-08 22:32:59 UTC
Got it to work by pointing to         public const string ApplicationServicesHIServicesFramework =