Bug 55941 - Cannot launch app in Debug build
Summary: Cannot launch app in Debug build
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 10.10 (d15-2)
Hardware: PC Windows
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-03 23:46 UTC by reemfz
Modified: 2017-07-27 17:20 UTC (History)
5 users (show)

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


Attachments
the logs from xamarin. (42.61 KB, application/x-zip-compressed)
2017-05-03 23:46 UTC, reemfz
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 NORESPONSE

Description reemfz 2017-05-03 23:46:23 UTC
Created attachment 21930 [details]
the logs from xamarin.

I've recently enrolled in Xamarin University and trying to follow some of the advance content, since I am fairly familiar with Xamarin basics.

I've been nothing but frustrated with my progress. The technology is plagued with bugs and for the past hour or so, all I've been doing is fighting with Xamarin, rather than making any sort of progress with the course.

Let me begin with some of the bugs:

EVERY sample project I downloaded from the course's materials, builds fine but is impossible to launch the iOS portion in debug mode. It will ONLY run in release. When I try to run in debug, all i get is  the following

Launching Application for debugging...
Launching Application for debugging...
Launching Application for debugging...
Launching Application for debugging...
Launching Application for debugging...

I can click on "Show iOS simulator" then VS launches the simulator just fine, but running the app - not chance. Restarting VS and my PC didn't make any difference. Again, I get no errors when I build the project and everything works in Android.

second bug

When I do run the app in release mode, VS does launches the app in the simulator but immediately I see the following in the console 

Loaded assembly: /Library/Frameworks/Xamarin.Interactive.framework/Versions/Current/Agents/iOS/Xamarin.Interactive.dll [External]
InspectorDebugSession(2): StateChange: BreakdanceInvoking -> BreakdanceStarted
InspectorDebugSession(2): HandleTargetEvent: TargetExited
InspectorDebugSession(2): Disposed
The app has been terminated.
Launch failed. The app 'App1' could not be launched on 'iPhone 7 iOS 10.3'. Error: An error occurred while executing MTouch. Please check the logs for more details.
The app has been terminated.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-04 03:27:32 UTC
Non-engineering team preliminary quick review
(See https://developer.xamarin.com/guides/cross-platform/troubleshooting/questions/howto-file-bug/ for general reference)




## Focuses on one problem?

Not exclusively.  The report describes one symptom, says "second bug," and then describes another symptom.  The remainder of this assessment will focus on the "Launching Application for debugging..." symptom in the "Debug|iPhoneSimulator" configuration.  If needed, a second bug report can be opened for the "second bug" once the initial assessment is complete for the first symptom.




## Includes information about the environment where the bug was encountered, including the operating system and versions of Xamarin and any dependencies?

Not completely yet.  The Xamarin.VisualStudio extension version is identified by the attached log file:
Xamarin.VS 4.4.0.34-d15-1+3f99c5a

Version details from the Mac are not yet included.




## Considers the relevant log files for the part(s) of the process where something goes wrong (IDE editing, MSBuild building, deploying, launching, attaching the debugger, an in-app error, or something else) and has them attached?

Yes. The attached log file from Comment 0 includes the following interesting excerpt:

> Xamarin.VisualStudio.Progress.ProgressReportService|Information|0|Launch succeeded. The app  'iOS Simulator' has been shown successfully in the Mac.
> Xamarin.VisualStudio.IOS.MonoTouchFlavoredProject|Error|0|An error occurred while lauching Application for debugging
> System.Net.NetworkInformation.NetworkInformationException (0x80004005): Invalid access to memory location
>    at System.Net.NetworkInformation.SystemIPGlobalProperties.GetAllTcpConnections()
>    at System.Net.NetworkInformation.SystemIPGlobalProperties.GetActiveTcpConnections()
>    at Xamarin.Messaging.Ssh.PortForwarder.IsPortAvailable(Int32 port) in C:\d\lanes\4471\3f99c5a7\source\xamarinvs\src\Messaging\Xamarin.Messaging.Ssh\PortForwarder.cs:line 139
>    at Xamarin.Messaging.Ssh.PortForwarder.GetAvailablePort(ConnectionSettings settings) in C:\d\lanes\4471\3f99c5a7\source\xamarinvs\src\Messaging\Xamarin.Messaging.Ssh\PortForwarder.cs:line 40
>    at Xamarin.VisualStudio.IOS.MonoTouchFlavoredProject.StartDebugging(MonoTouchDevice device, IProgressReport progress, MonoDebuggerLauncher debug_session) in C:\d\lanes\4471\3f99c5a7\source\xamarinvs\src\Core\VisualStudio.IOS\ProjectSystem\MonoTouchFlavoredProject.cs:line 868
>    at Xamarin.VisualStudio.IOS.MonoTouchFlavoredProject.<>c__DisplayClass71_0.<DebugApplication>b__0() in C:\d\lanes\4471\3f99c5a7\source\xamarinvs\src\Core\VisualStudio.IOS\ProjectSystem\MonoTouchFlavoredProject.cs:line 853



## Already took up time for many users?

Not yet it would seem.  This issue appears to depend on some details of the specific environment on the reporter's 2 computers.


- The exception message "Invalid access to memory location" does not appear in any other bugs on Bugzilla so far or in any xamarin-tagged questions on Stack Overflow.


- There are 2 reports on the forums that match that exception message, but they are both from more than 1 year ago, and the issue was resolved by by either (a) restarting Visual Studio, or (b) creating fresh user accounts on the Mac and Windows computers.

https://forums.xamarin.com/discussion/64238/socket-crash-when-waking-up-from-sleep
https://forums.xamarin.com/discussion/63979/vs-connect-to-mac-invalid-access-to-memory-location
 



## Makes development (a) difficult, impossible, or potentially hazardous, (b) moderately inconvenient, or (c) mildly inconvenient for users?

(a) Being able to use the debugger is a significant part of the normal development workflow.  While the reporter is currently able to make some forward progress, it would be difficult for the reporter to move forward with development while affected by this issue.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-04 03:29:55 UTC
## Recommended next steps for the reporter (reemfz)


1. Double-check that the Mac is up-to-date with the latest Xamarin Stable channel versions (https://developer.xamarin.com/recipes/cross-platform/ide/change_updates_channel/), and then collect and attach back your detailed version information from both computers:

- Windows: "Help > About Microsoft Visual Studio > Copy Info [button]"
- Mac: "Xamarin Studio > About Xamarin Studio > Show Details > Copy Information [button]"

(Importantly, this Xamarin Studio detailed version information will include your Mac OS version and your Xcode version.)


2. Also collect the Windows OS version from the Windows computer and add that to the bug report.


3. Ensure that Xamarin.iOS projects build, deploy, and launch as normal in the Debug configuration from Xamarin Studio directly on the Mac.


4. Try creating fresh new user accounts on both the Windows and Mac computers (based on the results from the forum threads mentioned above).




## Additional notes

The "Invalid access to memory location" exception during `System.Net.NetworkInformation.SystemIPGlobalProperties.GetAllTcpConnections()` appears in several other places in the log file.  It looks like that exception also interfered with some initial connection attempts for example.

One guess could be that some hardware details or system permissions details about the network interfaces could be involved in this issue.
Comment 3 reemfz 2017-05-04 04:11:27 UTC
Hello,

Thank you guys for looking into this.
I apologize for not including my systems info:

my primary development machine is a PC running Windows 7 64bit and Visual Studio 2017 with the most up to date release

as for my mac, it is running MacOS Sierra with most recent XCode. I also made sure Xamarin is up to date on my Mac as well. I double checked that both versions of Xamarin match.

With regards to creating new user accounts, that would be difficult because I use Active Directory accounts and if I log in with a local account, I will not be able to connect to network drives, wifi etc.

The Xamarin Mac Agent talks to my Mac over a wifi connection. When I reported the bugs I was able to connect to my Mac without any issues (at least I thought so). Although I was not able to launch the app in debug mode, I did manage to launch it in release mode. So that gave me the impression that the two are communicating but something gets broken as soon as I switch to debug.

Since I filed the bug report, I tried the following:

1) I restarted Visual Studio and created a brand new Xamain iOS single view project.
I built and ran the project in Debug and it worked. However as soon I stopped the debugger, I got the other error message: 
Launch failed. The app 'App1' could not be launched on 'iPhone 7 iOS 10.3'. Error: An error occurred while executing MTouch. Please check the logs for more details.

2) I then closed the new project solution and re-opened the solution I downloaded from xamarin university. Tried running it in debug and got same results. It won't launch.

3) I copied the solution to my Mac and tried directly from Xamarin Studio and it worked. Therefore, it must be something to do with either Visual Studio, the mac agent or the project from Xamarin University.

Once I get back to my office, I will reply back with all the requested information.

Thank you and sorry for the long reply.

Best,
Comment 4 reemfz 2017-05-04 17:35:17 UTC
## Recommended next steps for the reporter (reemfz)


1. Double-check that the Mac is up-to-date with the latest Xamarin Stable channel versions (https://developer.xamarin.com/recipes/cross-platform/ide/change_updates_channel/), and then collect and attach back your detailed version information from both computers:

- Windows: "Help > About Microsoft Visual Studio > Copy Info [button]"
- Mac: "Xamarin Studio > About Xamarin Studio > Show Details > Copy Information [button]"

(Importantly, this Xamarin Studio detailed version information will include your Mac OS version and your Xcode version.)

#### MY PC

Microsoft Visual Studio Professional 2017 
Version 15.1 (26403.7) Release
VisualStudio.15.Release/15.1.0+26403.7
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Professional

Visual Basic 2017   00370-10000-70240-AA842
Microsoft Visual Basic 2017

Visual C# 2017   00370-10000-70240-AA842
Microsoft Visual C# 2017

Visual C++ 2017   00370-10000-70240-AA842
Microsoft Visual C++ 2017

Visual F# 4.1   00370-10000-70240-AA842
Microsoft Visual F# 4.1

ASP.NET and Web Tools 2017   15.0.30320.0
ASP.NET and Web Tools 2017

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

CreateLayoutWizard   1.0
Create layout wizard.

DevExpress.DeploymentTool   1.0
A useful tool for deploying DevExpress assemblies.

JavaScript Language Service   2.0
JavaScript Language Service

JetBrains ReSharper Ultimate 2017.1.1    Build 108.0.20170407.122957
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2017 JetBrains, Inc.

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Visual Studio tools for CMake   1.0
Visual Studio tools for CMake

Xamarin   4.4.0.34 (3f99c5a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.2.0.7 (b16fb82)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.8.0.174 (7656cc6)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

## MY MAC

=== Xamarin Studio Community ===

Version 6.3 (build 863)
Installation UUID: 3898f045-9c8f-445d-8ae9-7d724ff02e5a
Runtime:
	Mono 4.8.1 (mono-4.8.0-branch/22a39d7) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408010000

=== NuGet ===

Version: 3.5.0.0

=== Xamarin.Profiler ===

Version: 1.4.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.3.2 (12175)
Build 8E2002

=== Xamarin.Mac ===

Version: 3.2.0.175 (Xamarin Studio Community)

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Xamarin.Android ===

Version: 7.2.0.7 (Xamarin Studio Community)
Android SDK: /Users/rfazio/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		6.0 (API level 23)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.iOS ===

Version: 10.8.0.175 (Xamarin Studio Community)
Hash: a04678c2
Branch: d15-1
Build date: 2017-03-28 14:05:38-0400

=== Build Information ===

Release ID: 603000863
Git revision: a2163670efe259c85cd8f335d95b175068fbbe2a
Build date: 2017-04-03 14:33:15-04
Xamarin addins: 2045d688ea1420e0381b473360ca62a763eb7d04
Build lane: monodevelop-lion-d15-1

=== Operating System ===

Mac OS X 10.12.4
Darwin LA-C02HK0TRDV10 16.5.0 Darwin Kernel Version 16.5.0
    Fri Mar  3 16:52:33 PST 2017
    root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64




2. Also collect the Windows OS version from the Windows computer and add that to the bug report.

Windows 7 Enterprise
Service Pack 1

RAM: 32.0 GB 
System type: 64-bit Operating System


3. Ensure that Xamarin.iOS projects build, deploy, and launch as normal in the Debug configuration from Xamarin Studio directly on the Mac.

I am now certain that the issues I am having are related to the outdated projects from Xamarin University. They will not run on my PC or from Xamarin Studio on my Mac. On the PC I get "Launching application for debugging" and nothing happens. On my Mac, in Xamarin Studio, they won't even compile. I get errors like "You must add references to assembly System.Runtime Version 4.0.2 "

However, in both PC and Mac, if I create a brand new project I can build and run them in debug or release without any issues. The only difference is that in my PC, after I stop the debugger in VS, I get this weird message: 
Launch failed. The app 'App1' could not be launched on 'iPhone 7 iOS 10.3'. Error: An error occurred while executing MTouch. Please check the logs for more details.
The app has been terminated.

which I do not get in Xamarin Studio on the mac.

4. Try creating fresh new user accounts on both the Windows and Mac computers (based on the results from the forum threads mentioned above).

unfortunately, due to company restrictions and group policy I am unable to do that.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-04 21:33:19 UTC
Excellent.  Many thanks for the additional details.




## Quick note about "Launch failed message"

First just a quick note to clear up any confusion about the "Launch failed message":

> The only difference is that in my PC, after I stop the debugger in VS,
> I get this weird message: 
> 
> Launch failed. The app 'App1' could not be launched on 'iPhone 7 iOS
> 10.3'. Error: An error occurred while executing MTouch. Please check
> the logs for more details.  The app has been terminated.
This is a known confusing little usability issue: Bug 53139.  That message should in theory not interfere with other functionality, so we can set it aside for the moment for the purposes of this bug.  I have added a note on Bug 53139 to keep a tally of your report of the issue.




## Version information, quick skim

The version information looks pretty good to me.  The use of Windows 7 is potentially interesting.  I ran across an unusual failure of a Windows networking API with another user on Windows 7 a while back in Bug 39027.  Admittedly, the exact API and error from that bug were a bit different, but there's a chance that both that old bug and this new issues are related to certain edge case bugs in the networking APIs in Windows 7 that don't affect Windows 8.1 and higher.




## Active Directory accounts

> I use Active Directory accounts
This is also potentially interesting.  There have been a small number of reports from users where using Active Directory to log in on the Mac caused trouble for the remote Mac connection, but in those older cases the issue interfered with the initial connection process rather than debugging.  So we can probably set aside that exact issue for the moment.

For the Windows side, one rough guess could be that an Active Directory domain restriction might be related to the exception in `SystemIPGlobalProperties.GetAllTcpConnections()`.  For example, maybe the AD domain settings are exposing an edge case issue in the Windows 7 networking APIs.




## WiFi

At least in the past there were some reports from users about timeout issues when using a WiFi connection between the 2 machines, but it seems that's not quite the problem in this case.  Based on a quick glance through the documentation for `GetAllTcpConnections()` [1], it sounds like WiFi could _possibly_ increase the chances of a problem, if for example that method (at least on Windows 7) is not entirely robust against various kinds of intermittent failures or changes in TCP connections (that might be more common with WiFi).  But again that is just a rough guess.

[1] https://msdn.microsoft.com/library/system.net.networkinformation.ipglobalproperties.getipglobalproperties.aspx




## Xamarin University projects

> On my Mac, in Xamarin Studio, they won't even compile. I get errors like "You
> must add references to assembly System.Runtime Version 4.0.2 "
That failure on Mac sounds interesting, at least as something to keep in mind as we move forward with the bug.

I'd have to look into it a bit more to see what is unique about the Xamarin University project(s), but at a first glance this looks like it might be an edge case related to PCL facade assemblies or similar, maybe caused by a certain NuGet package version, and perhaps also involving .NET Standard.  It looks like there is one other user mention of this issue on the forums:

https://forums.xamarin.com/discussion/93742/object-is-defined-in-an-assembly-that-is-not-referenced
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-04 21:33:32 UTC
## Possible next steps

1. If you find that new projects all behave OK and you are able to proceed fairly smoothly that way, that might be one somewhat "minimalist" way to move forward.  We can leave the bug open for now, and you can come back to this bug if for example you find that you do indeed start hitting the issue as soon as the applications get bigger than a certain size (or something similar).

2. Depending on what options you have available for extra environment tests, it could be interesting to try switching around some parts of the scenario.  For example if you have the option to try a Windows 8.1 system (or a different Windows 7 system) connected to the same Mac, on the same network, logged into the same AD domain, that might be interesting.

3. It might be interesting to try stress-testing the `SystemIPGlobalProperties.GetAllTcpConnections()` API on your system in a C# console application or similar.  I can potentially play around with setting up a tiny test application for that over the next few days.
Comment 7 Alex Soto [MSFT] 2017-06-19 16:01:13 UTC
Hello, is this still an issue?
Comment 8 reemfz 2017-06-19 18:12:15 UTC
Hello,

I haven't had a chance to test it on my pc at home which runs Windows 10 and VS2017.

However, using my office PC (Windows 7, VS2017),  I am still able to reproduce the issue.

on the mac, using either visual studio or Xamarin studio, I never get this error/issue
Comment 9 Al Clark [MSFT] 2017-07-27 17:20:05 UTC
Since it's been a while since your last response we are marking this issue as RESOLVED→NORESPONSE. If you are still encountering this issue on the latest Xamarin.iOS 10.12.0.14 and a different system, please don’t hesitate to reopen the ticket with the requested information. Thanks!