Bug 25936 - Setting icons for tabbed pages causes System.Exception when iOS app is launched.
Summary: Setting icons for tabbed pages causes System.Exception when iOS app is launched.
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-12 13:36 UTC by Jon Goldberger [MSFT]
Modified: 2015-07-30 11:41 UTC (History)
8 users (show)

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

Description Jon Goldberger [MSFT] 2015-01-12 13:36:56 UTC
## Description

iOS app fails to launch a Xamarin Forms app if an icon is set on a NavigationPage which is a child of a TabbedPage.

## Steps to reproduce

1. Download both zip files from the link in the private comment below.
2. Unzip both files and open the MemberPortal solution in the MemberPortal folder.
3. in the HPSJCore.Portable project you will have to delete the reference to Newtonsoft.Json and then add the JSON.Net nuget package.
4. Select the iOS project as the startup project.
5. Launch the iOS app.

Expected result: UI will appear with a tab bar with three tabs and icons for each tab

Actual result: App crashes with the following exception:

>System.Exception: Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil.
>It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.
>  at Foundation.NSObject.InitializeHandle (IntPtr handle, System.String initSelector) [0x00094] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:463
>  at UIKit.UIImage..ctor (System.String filename) [0x0002e] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIImage.g.cs:91
>  at Xamarin.Forms.Platform.iOS.TabbedRenderer.SetupPage (Xamarin.Forms.Page page, Int32 index) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.TabbedRenderer.Reset () [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.NotifyCollectionChangedEventArgsExtensions.Apply (System.Collections.Specialized.NotifyCollectionChangedEventArgs self, System.Action`3 insert, System.Action`2 removeAt, System.Action reset) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPagesChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.TabbedRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.Platform.AddChild (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.Platform.WillAppear () [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.PlatformRenderer.ViewWillAppear (Boolean animated) [0x00000] in <filename unknown>:0
>  at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
>  at UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/build/native/UIKit/UIWindow.g.cs:247
>  at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.SetMainPage () [0x00000] in <filename unknown>:0
>  at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.FinishedLaunching (UIKit.UIApplication uiApplication, Foundation.NSDictionary launchOptions) [0x00000] in <filename unknown>:0
>  at MemberPortal.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0002f] in /Users/apple/Downloads/MemberPortal/MemberPortal/MemberPortal.iOS/AppDelegate.cs:48
>  at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
>  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
>  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
>  at MemberPortal.iOS.Application.Main (System.String[] args) [0x00008] in /Users/apple/Downloads/MemberPortal/MemberPortal/MemberPortal.iOS/Main.cs:16


## Note

I was not able to replicate this in a simpler app that set a NavigationPage as a child of a TabbedPage, so I am not sure exactly what is causing the issue. I did test to see if having an @2x version of the icon helped resolve the issue, but it did not. 

However commenting out the lines that set the icons for the pages resolves the issue but then there are no icons on the tabs. To verify, comment out lines 172, 200, and 212 of the App.cs file in the MemberPortal project and relaunch the iOS app. The app then launches as expected but without any icons for the tabs. 

## Version info

Xamarin Forms 1.3.1.6294-pre1 (also tested on 1.3.1.6296)

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.10.1
Darwin Jons-iMac.local 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 3 Sunil Kumar 2015-01-13 05:43:44 UTC
I have tried to reproduce this issue and able to reproduce. I am getting the same exception mentioned in bug description. I followed steps mentioned in bug description to reproduce this issue.

Screencast: http://www.screencast.com/t/sKihExo7
Exception: https://gist.github.com/sunil360/c18bfb847c69983a83c0
IDE log: https://gist.github.com/sunil360/812792decfe9049c9b39
iOSdesigner Log: https://gist.github.com/sunil360/24006e88af0fd1bb9770

Environment info: 
=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 561c7a69-0a91-4bae-ad7c-f0c79d594337
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.6.0.51 (Trial Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Trial Edition)
Android SDK: /Users/tajinder/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: 1.12.0.0 (Trial Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.8.4
Darwin Tajinders-iMac.local 12.4.2 Darwin Kernel Version 12.4.2
    Mon Jun 17 18:00:12 PDT 2013
    root:xnu-2050.45.8~1/RELEASE_X86_64 x86_64
Comment 4 Jon Goldberger [MSFT] 2015-01-14 20:28:28 UTC
Note:

I was able to fix this issue with the workaround posted by Jeffrey in bug https://bugzilla.xamarin.com/show_bug.cgi?id=25569

From that post:

"The following change to your Xamarin.iOS.Common.targets file should solve this
issue:

--- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
+++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
@@ -217,7 +217,7 @@ Copyright (C) 2013-2014 Xamarin. All rights reserved.
        </PropertyGroup>

        <!-- TODO: check for duplicate items -->
-       <Target Name="_CopyContentToBundle"
+       <Target Name="_CopyContentToBundle"
DependsOnTargets="_CollectBundleResources"
                Inputs = "@(_BundleResourceWithLogicalName)"
                Outputs = "@(_BundleResourceWithLogicalName ->
'$(_AppBundlePath)%(LogicalName)')" >
                <Copy


(i.e. just add the DependsOnTargets XML property/value)"

The file is located at: 
/Library/Frameworks/Xamarin.iOS.framework/Versions/8.6.0.51/lib/mono/2.1/Xamarin.iOS.Common.targets

and is not editable by user, so I opened the file in vi (or nano) in terminal using sudo. I then made the edit and saved and the image loading issue (and other controls not being rendered) issue was resolved.
Comment 5 srobbins103 2015-01-21 12:13:16 UTC
Also struggled with this, will it be fixed soon please?
Comment 6 Jon Goldberger [MSFT] 2015-01-23 13:06:58 UTC
@srobbins103,

There is a workaround. See comment 4.
Comment 7 Jason Smith [MSFT] 2015-01-26 04:49:29 UTC
This is an issue with Xamarin.iOS, please see the workaround in comment 4.
Comment 8 Alessandro 2015-07-29 16:26:30 UTC
Hi Jason. In iOS 7.1 simulator (iPhone 4)...

I've already this code      

  <!-- TODO: check for duplicate items -->
        <Target Name="_CopyContentToBundle" DependsOnTargets="_CollectBundleResources;_GenerateBundleName"
                Inputs = "@(_BundleResourceWithLogicalName)"
                Outputs = "@(_BundleResourceWithLogicalName -> '$(_AppBundlePath)%(LogicalName)')" >
                <SmartCopy
                        SessionId="$(BuildSessionId)"
                        Condition="'$(MtouchTargetsEnabled)'"
                        SourceFiles = "@(_BundleResourceWithLogicalName)"
                        DestinationFiles = "@(_BundleResourceWithLogicalName -> '$(_AppBundlePath)%(LogicalName)')"
                />
        </Target>

but I have this exception

Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil.
It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.


at Foundation.NSObject.InitializeHandle (IntPtr handle, System.String initSelector) [0x00094] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/Foundation/NSObject2.cs:465 
  at UIKit.UIImage..ctor (System.String filename) [0x0002e] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/build/ios/native/UIKit/UIImage.g.cs:91 
  at Xamarin.Forms.Platform.iOS.TabbedRenderer.SetupPage (Xamarin.Forms.Page page, Int32 index) [0x0003f] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.TabbedRenderer.Reset () [0x0001c] in <filename unknown>:0 
  at Xamarin.Forms.NotifyCollectionChangedEventArgsExtensions.Apply (System.Collections.Specialized.NotifyCollectionChangedEventArgs self, System.Action`3 insert, System.Action`2 removeAt, System.Action reset) [0x001dd] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.TabbedRenderer.OnPagesChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.TabbedRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00063] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x0001c] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00025] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+<OnPushAsync>d__1c.MoveNext () [0x0000d] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1962/8b265d64/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/1962/8b265d64/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/1962/8b265d64/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/1962/8b265d64/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 
  at System.Runtime.CompilerServices.TaskAwaiter`1[System.Boolean].GetResult () [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:372 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+<<ViewDidLoad>b__3>d__4.MoveNext () [0x0006c] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1962/8b265d64/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1006 
  at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIKitSynchronizationContext.cs:24 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/Foundation/NSAction.cs:164 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:63 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1962/8b265d64/source/maccore/src/UIKit/UIApplication.cs:47 
  at CRMLight.iOS.Application.Main (System.String[] args) [0x00008] in /Users/alessandrocaliaro/Projects/Soluzione1/crm-light/iOS/Main.cs:16
Comment 9 Alessandro 2015-07-30 11:41:44 UTC
Ok, found the problem.
I have to insert the filename extension in "Icon" property (ex: Icon = "file.png")