Bug 18102 - NSImage.ImageNamed returns null is image is in a sub folder
Summary: NSImage.ImageNamed returns null is image is in a sub folder
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.6.34
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
Depends on:
Reported: 2014-02-28 16:46 UTC by Zhenya
Modified: 2014-03-01 20:38 UTC (History)
1 user (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 Zhenya 2014-02-28 16:46:52 UTC
Can't always load NSImage by calling NSImage.ImageNamed. Steps:
1) Put Image.png to "Resources/Images" sub-folder.
2) Try loading the image by calling NSImage.ImageNamed("Resources/Images/Image.png") or NSImage.ImageNamed("Image.png").
Result: returned image is null
Expected: image is not null
Workaround: put Image.png to the Resources folder and load it by calling NSImage.ImageNamed("Image.png")
Comment 1 Aaron Bockover [MSFT] 2014-02-28 17:30:09 UTC
I believe this is the intended behavior. Xamarin.Mac doesn't do anything special here - it just calls the NSImage imageNamed: selector.

You can use methods on NSBundle to get the full path of an image inside the bundle and then load NSImage from a file. From what I understand, imageNamed: does not search subdirectories (this would likely be rather slow).

See for more details:


Comment 2 Zhenya 2014-03-01 20:38:34 UTC
Got it, thanks.