Bug 24035 - Bundle does not return correct executable name from application name
Summary: Bundle does not return correct executable name from application name
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.10.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2014-10-24 06:56 UTC by Andreja
Modified: 2014-12-05 12:16 UTC (History)
2 users (show)

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


Attachments
firefox info.plist file (5.41 KB, application/octet-stream)
2014-10-24 06:56 UTC, Andreja
Details


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:
Status:
RESOLVED ANSWERED

Description Andreja 2014-10-24 06:56:28 UTC
Created attachment 8496 [details]
firefox info.plist file

I've tested this piece of code with various apps and they get me correct path to the application.
For some reason firefox returns different name. This worked correctly for Firefox in OSX Maverics but does not work on Yosemite. 

Xamarin version: 1.10.0.18 (Business Edition)

public static object BundleNamesFromApplicationName(string name)
		{
			var workspace = MonoMac.AppKit.NSWorkspace.SharedWorkspace;
			var path = workspace.FullPathForApplication(name);

			if (!string.IsNullOrEmpty(path))
			{
				var bundle = new MonoMac.Foundation.NSBundle(path);
				return new { 
					Name = bundle.InfoDictionary["CFBundleName"].ToString(),
					Executable = bundle.InfoDictionary["CFBundleExecutable"].ToString()
				};
			}

			return null;
		}


The expected output: firefox

Actual output: WinAppHelper

Note: if I enter safari or some other app it gives me correct application path i.e. /Applications/Safari

I've included info.plist from firefox as it looks same as it was on Mavericks.

fullpathforapplication : //path	"/Users/ajovanovic/Applications (Parallels)/{e52a80d7-14fd-4c8c-a0be-347d3297454f} Applications.local…"	string

note: bundle returned

InfoDictionary	{{     CFBundleDevelopmentRegion = English;     CFBundleDocumentTypes =     (                 {             CFBundleTypeExtensions =             (                 "*"             );             CFBundleTypeMIMETypes =             (                 "*/*"             );             CFBundleTypeOSTypes =             (                 "****"             );             CFBundleTypeRole = Editor;         },                 {             CFBundleTypeExtensions =             (                 shtml             );             CFBundleTypeIconFile = "my_documents.icns";             CFBundleTypeName = "SHTML File";             CFBundleTypeRole = Editor;         },                 {             CFBundleTypeExtensions =             (                 xht             );             CFBundleTypeIconFile = "my_documents.icns";             CFBundleTypeName = "XHT File";             CFBundleTypeRole = Editor;         },                 {             CFBundleTypeExtensions =             (                 xhtml             );             CFBundleTypeIconFile = "my_documents.icns";             CFBundleTypeName = "XHTML File";             CFBundleTypeRole = Editor;         },                 {             CFBundleTypeExtensions =             (                 msi             );             CFBundleTypeIconFile = "my_documents.icns";             CFBundleTypeName = "MSI File";             CFBundleTypeRole = Editor;         }     );     CFBundleExecutable = WinAppHelper;     CFBundleGetInfoString = "9.8, C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";     CFBundleIconFile = "WinAppHelper.icns";     CFBundleIdentifier = "com.parallels.winapp.763f7f1aec350cd1a46238d1d5c3c229.e52a80d714fd4c8ca0be347d3297454f";     CFBundleInfoDictionaryVersion = "6.0";     CFBundleInfoPlistURL = "Contents/Info.plist -- file://localhost/Users/ajovanovic/Applications%20(Parallels)/%7Be52a80d7-14fd-4c8c-a0be-347d3297454f%7D%20Applications.localized/Firefox.app/";     CFBundleName = Firefox;     CFBundleNumericVersion = 0;     CFBundlePackageType = APPL;     CFBundleShortVersionString = "Windows 8";     CFBundleSignature = "????";     CFBundleURLTypes =     (                 {             CFBundleTypeRole = Editor;             CFBundleURLName = "Supported protocols";             CFBundleURLSchemes =             (                 ftp,                 http,                 https             );         }     );     CFBundleVersion = "9.0.24237.1028877";     CSResourcesFileMapped = 1;     LSBackgroundOnly = 1;     LSHasLocalizedDisplayName = 1;     LSUIElement = 1;     NSHighResolutionCapable = 1;     NSPrincipalClass = NSApplication; }}	MonoMac.Foundation.NSMutableDictionary
Comment 1 Andreja 2014-10-24 10:07:10 UTC
Ok I've run it again with Parallels 10 installed.
Run the app from application folder and it gave me correct path to Firefox.
i.e. firefox
I'm not sure what has gone wrong in first instance. Or I was pointing to debug version from spotlight when I run application.
Comment 2 Sadik Ali 2014-10-28 07:53:15 UTC
I have checked this issue but I am unable to reproduce this issue.

I have checked this behavior with both classic API and unified API project and observed that I am getting the correct executable name for firefox.

Screencast: http://www.screencast.com/t/oQOoxO4pxlG

Could you please provide sample application and build information? So that we can reproduce this issue at our end.

You can get build information from here:

Xamarin Studio=> About Xamarin Studio => Show Details => Copy Information

Environment Info:

Mac OS X 10.10.0
Xamarin Studio : 5.5.2 (build 3)
Mono 3.10.0 ((detached/e204655)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.0.1 (6528)
Xamarin.Mac: 1.10.0.19 (Business Edition)
Build Information
Release ID: 505020003
Git revision: 6d4c806e383ba366b15fbccca9ddc1ba94f8d5ad
Build date: 2014-10-15 15:00:36-04
Xamarin addins: 069ddd29bb70a42238142eee9bac21a5e4b2f9f9
Comment 3 Andreja 2014-10-28 08:11:40 UTC
Could not reproduce it as well after installing Parallels 10.
I was using Yosemite OSX.
I think I was running in development environment.

Xamarin Studio
Version 5.5.2 (build 3)

Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

Apple Developer Tools
Xcode 6.1 (6604)
Build 6A1052d

Xamarin.iOS
Not Installed

Xamarin.Android
Not Installed

Xamarin.Mac
Version: 1.10.0.18 (Business Edition)

Build Information
Release ID: 505020003
Git revision: 
Build date: 2014-10-15 15:00:36-04
Xamarin addins: 069ddd29bb70a42238142eee9bac21a5e4b2f9f9

Operating System
Mac OS X 10.10.0
Darwin  14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 4 Andreja 2014-10-28 08:13:03 UTC
Could not reproduce it as well after installing Parallels 10.
I was using Yosemite OSX.
I think I was running in development environment.

Xamarin Studio
Version 5.5.2 (build 3)

Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

Apple Developer Tools
Xcode 6.1 (6604)
Build 6A1052d

Xamarin.iOS
Not Installed

Xamarin.Android
Not Installed

Xamarin.Mac
Version: 1.10.0.18 (Business Edition)

Build Information
Release ID: 505020003
Git revision: 
Build date: 2014-10-15 15:00:36-04
Xamarin addins: 069ddd29bb70a42238142eee9bac21a5e4b2f9f9

Operating System
Mac OS X 10.10.0
Darwin  14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 5 Andreja 2014-11-05 06:13:57 UTC
I got this again on debug and also on released app (release for Skype).

This time it happens for Skype I had process name as WinAppHelper as the path to the app is not full.

It may have to do something with Parallels 10 installed on my computer.

Certain apps get correct full path i.e. /Applications/Google Chrome.app

but then fro skype and firefox

skype --> /Users/ajovanovic/Applications (Parallels)/{e52a80d7-14fd-4c8c-a0be-347d3297454f} Applications.localized/Skype.app

for firefox --> /Users/ajovanovic/Applications (Parallels)/{e52a80d7-14fd-4c8c-a0be-347d3297454f} Applications.localized/Firefox.app

Note: Parallels 10 is switched off it's not working. And I'm selecting apps from Applications folder on OSX therefore the path should be same for Google Chrome for all of them.

I get through file browsers list of apps from OSX apps folder.

the code is below for test



public Application GetApplicationFromName(string name)
		{
			var workspace = MonoMac.AppKit.NSWorkspace.SharedWorkspace;

			var path = workspace.FullPathForApplication(name);

			if (!string.IsNullOrEmpty(path))
			{
				var bundle = new MonoMac.Foundation.NSBundle(path);
				return new Application()
				{ 
					Name = bundle.InfoDictionary["CFBundleName"].ToString(),
					ProcessName = GetCorrectApplicationName(bundle.InfoDictionary["CFBundleExecutable"].ToString()),
					Enabled = false
				};
			}

			return null;
		}
Comment 6 Andreja 2014-11-05 06:15:23 UTC
Xamarin Studio
Version 5.5.3 (build 6)
Installation UUID: 
Runtime:
	Mono 3.10.0 ((detached/e204655)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000023

Apple Developer Tools
Xcode 6.1 (6604)
Build 6A1052d

Xamarin.iOS
Not Installed

Xamarin.Android
Not Installed

Xamarin.Mac
Version: 1.10.0.18 (Business Edition)

Build Information
Release ID: 505030006
Git revision: 
Build date: 2014-10-23 13:08:38-04
Xamarin addins: 

Operating System
Mac OS X 10.10.0
Darwin Andrejas-MBP 14.0.0 Darwin Kernel Version 14.0.0
Comment 7 Andreja 2014-11-05 09:38:36 UTC
I found quick fix to this issue.
I went to Configuration of parallels and switches windows applications from being visible.

So what has happened. 
We have mac osx Applications folder and 
                Applications (Parallels) folder

so for apps that were unique to OSX everything was fine but for apps that were common to both Windows and OSX there was issue as it chose Windows path as opposed to OSX path first.


note: The filedialog was opening by default my Applications folder for mac apps and I passed only name. e.g. firefox

So the function var path = workspace.FullPathForApplication(name);
is not choosing correct path to mac app but to windows parallels apps.

I hope this helps.
Comment 8 Andreja 2014-11-05 09:41:17 UTC
One more thing I forgot to mention as I had Applications (Parallels) i had to delete it before it actually chose correct Applications folder.
Moving it to trash it could still find apps.
Comment 9 Chris Hamons 2014-12-05 11:37:45 UTC
Andreja,

I'm not sure this is a bug with Xamarin.Mac. We're exposing the underlying APIs with little changes, it sounds like Parallels is just mucking with this (via this WinAppHelper).

Do you have an example without parallels installed or a version in objective-c that has different behavior?
Comment 10 Andreja 2014-12-05 11:48:16 UTC
Nope just the one with Xamarin. I do not program in objective C.
If it's direct Xcode API (NBundle) call that is making issue, then I guess it should be raised with Apple team.
Comment 11 Andreja 2014-12-05 11:49:14 UTC
If NsBundle is direct Apple Cocoa Api let me know and I will close the issue with Xamarin.
Comment 12 Chris Hamons 2014-12-05 11:52:57 UTC
NSBundle is an API that apples exposes on iOS and Mac.

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/index.html

In general, we try to expose the API to c# with as few changes as possible. I find it unlikely that we're changing behavior in this case (Especially to something like WinAppHelper). If the property crashed, or return garbage string, then our binding could be the problem.

Until proven otherwise, I believe we're exposing the result of the NSBundle call correctly, it just isn't giving the answer you desire.
Comment 13 Andreja 2014-12-05 12:16:39 UTC
Ok I will raise issue with Apple as it might be that NSBundle get consfued when parallels is installed with folders of different OS.