Bug 18225 - IPA Built with mdtool Crashes on Launch
Summary: IPA Built with mdtool Crashes on Launch
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.0.7
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-03-06 13:42 UTC by abe
Modified: 2017-01-30 22:56 UTC (History)
5 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 NOT_REPRODUCIBLE

Description abe 2014-03-06 13:42:51 UTC
I build my iOS app project on a Mac, using mdtool, specifically this one: 

Applications/Xamarin Studio.app/Contents/MacOS/mdtool

It builds fine, generates an IPA, which I am able to successfully install on my device. However, the app crashes immediately upon launch.

Looking at the console log in iPhone Configuration Utility, I see: 

Mar  6 11:27:08 ipod4 MyAppiOS[177] <Warning>: MonoTouch: Could not find the required assembly 'MyAppiOS.exe' in the app. This is usually fixed by cleaning and rebuilding your project; if that doesn't work, please file a bug report: http://bugzilla.xamarin.com
Mar  6 11:27:08 ipod4 com.apple.launchd[1] (UIKitApplication:com.mycompany.myapp[0xd91b][177]) <Error>: (UIKitApplication:com.mycompany.myapp[0xd91b]) Exited with code: 1
Mar  6 11:27:08 ipod4 com.apple.launchd[1] (UIKitApplication:com.mycompany.myapp[0xd91b]) <Notice>: (UIKitApplication:com.mycompany.myapp[0xd91b]) Throttling respawn: Will start in 2147483647 seconds
Mar  6 11:27:08 ipod4 backboardd[26] <Warning>: Application 'UIKitApplication:com.mycompany.myapp[0xd91b]' exited abnormally with exit status 1

Tried cleaning and rebuilding, same crash happens.

So I have created this bug as suggested by the MonoTouch warning message.

Notes:
- building my app through VS on my windows machine works fine, on both device and simulator.
- my app is three projects, a PCL library, an iOS library, and the iOS app project.
Comment 1 Ram Chandra 2014-03-07 05:59:30 UTC
I have checked this issue but I am unable to reproduce this issue.

Steps to reproduce

1. Create a "iPhone application" on "Xamarin Studio".
2. Set the ad-hoc provision profile (Project Option -> iOS Bundle Signing).
3. Run following command on terminal
 
/Applications/Xamarin Studio.app/Contents/MacOS/mdtool' -v build '--configuration:Ad-Hoc|iPhone' bug_18225.sln

4. Build Successful and IPA file generated on location "ProjectName (In my case bug_18225) -> bin -> iPhone -> Ad-Hoc -> bug_18225-1.0.ipa".

5. Install IPA file on device. 
Application is running successfully on device

Environment:

Mac OS
Xamarin Studio : 4.2.3 (build 59)
Xamarin.iOS : 7.0.7.2 
iPhone 5c  (iOS 7.1 beta5)

Please let me know if  you are getting this issue on specific project or if I have missed anything ?
Comment 2 abe 2014-03-10 21:07:05 UTC
I tried the steps you provided here, the blank new iphone application built and ran fine using mdtool.

The same exact steps using my solution produce an IPA that immediately crashes upon running.

Any suggestions on how to proceed? I can try to strip out parts of my app until it works, as much as I don't like to do that.
Comment 3 Jeffrey Stedfast 2014-03-10 21:11:40 UTC
Perhaps the device log would be useful. Can you use Xcode's Organizer to grab the device log when this happens?

The problem might be an expired provisioning profile or something. Or perhaps the provisioning profile doesn't include the device you are installing onto.
Comment 4 abe 2014-03-10 21:22:25 UTC
I used xcode's organizer and I obtained the device log as requested:
Comment 6 abe 2014-03-10 21:23:44 UTC
As for expired provisioning profile, or invalid for device, I doubt it, since I can open the same exact project in VS ( or in XS on the mac) and build and deploy to the same device successfully.
Comment 7 abe 2014-03-10 21:40:33 UTC
Where does xamarin studio place it's IPA before it uploads to device? Maybe I can unzip the two IPA files and compare those? Is it possible mdtool is failing to use the right provisioning profile or something? (though my command is exactly as you provided..)
Comment 8 Jeffrey Stedfast 2014-03-10 22:22:33 UTC
It doesn't create an IPA to install it on device, it just copies the .app directory over afaik.

And the way the .IPA is created is just zip -r if the .app directory.

Anyway, the device log doesn't suggest it has anything to do with provisioning profiles. Looks like the app is getting an abort.

No idea why it crashes only when installing via .IPA.

Maybe the iOS team can look at the crash and figure out the problem.
Comment 9 Jeffrey Stedfast 2014-03-10 22:24:50 UTC
Oh, hmmm, the error message in your first comment probably explains it. No clue why the .exe is not being built, tho, that makes no sense.

Can you attach your build log from mdtool?
Comment 10 abe 2014-03-11 13:47:09 UTC
Here is the build log from mdtool:
Comment 19 abe 2014-03-13 21:52:30 UTC
Things I will try:
- Comparing the .sln and the .csproj files between my solution and the empty one that works
- Creating an empty ios project on visual studio rather than on Xamarin studio to see if that works
- Taking out pages/features from my app (remove server communication, remove google maps, remove PCL library, one part at a time)

Please let me know if there are other suggestions.
Comment 23 Rolf Bjarne Kvinge [MSFT] 2014-03-14 04:46:47 UTC
Yes, you can treat the IPA file as a normal ZIP file and just replace the .exe with the working version.
Comment 24 abe 2014-03-14 15:00:47 UTC
Ok, I was able to replace the .exe. I had to:
- unzip the .ipa
- remove the old codesigning info
- replace the .exe
- resign the .ipa (I copied the command used from the build output, it was using a string as the value for the certificate, and I have no idea how I would use this command in my automated build...)
- re-zip the unzipped .ipa

This worked, as a temporary workaround, but I don't even know if I can use this because I don't know where to obtain the value for the certificate in the codesigning command.
Comment 25 abe 2014-03-17 12:26:21 UTC
Empty iOS application created with VS, copied solution folder to the mac and ran a build there using mdtool. Generated IPA has a valid (non-zero-byte) .exe file, and it runs fine without crashing on my device.

This points to something specific about my project. I will proceed to separate chunks out of my project until it works.
Comment 26 abe 2014-03-17 18:09:54 UTC
Here is the code block that causes the build to fail:


ResortTableView tbl1 = tbl; // avoid access to foreach var in closure warning
tbl.Button.TouchUpInside += async delegate(object sender, EventArgs args)
{
    if (tbl1.HasSubcategories) // don't expand if category has no subcategories
    {
        if (tbl1.Hidden)
        {
            tbl1.Show();
            tbl1.Button.Expand();
            foreach (var btn in buttons)
            {
                btn.BackgroundColor = btn.Frame.Width.Equals(View.Bounds.Width) ? btn.DataBackgroundColour : UIColor.LightGray;
            }
        }
        else
        {
            tbl1.Hide();
            tbl1.Button.Collapse();
            if (buttons.Any(btn => btn.Frame.Width.Equals(View.Bounds.Width)))
                foreach (var btn in buttons)
                {
                    btn.BackgroundColor = btn.Frame.Width.Equals(View.Bounds.Width) ? btn.DataBackgroundColour : UIColor.LightGray;
                }
            else
            {
                foreach (var btn in buttons)
                {
                    btn.BackgroundColor = btn.DataBackgroundColour;
                }
            }
        }
        await Task.Delay(120); // a bit of delay to ensure the Hidden property is set for the table, otherwise the next line will have the wrong numbers
        tbl1.UpdateScrollViewContentSize();
    }
};


I tried to narrow it down further, and I think it has something to do with the foreach's and with the .Any() but I get inconsistent results. I will try to rewrite my code (it needs cleanup anyway) but as far as I can tell this would be a bug in xamarin/mono. I'm open to your comments.
Comment 27 abe 2014-03-17 18:40:38 UTC
Rewriting the above code to not use anything from outside the closure, and getting "buttons" as a List instead of an Enumerable makes the build work fine! 

I don't know why the build succeeded through Visual Studio but not directly in mdtool, and I don't know why the build failed at all, I expect something like this to be a runtime error if anything? Finally, it is very confusing that it produces an invalid IPA and tells me that the build succeeded, it would have saved so much time if it just failed and told me why!

Anyway, I can now move forward.
Comment 28 Vincent Dondain [MSFT] 2017-01-30 22:56:32 UTC
Hi,

Glad you found a workaround.

We never had any other similar reports since then (2014), if you can still duplicate it and give us access to your original code (or a test case that can help us reproduce the issue) we’ll debug it. In the meantime let me close this bug as NOT_REPRODUCIBLE.

Note: Mono has evolved a great deal since 2014 so this might not be an issue anymore.