Reputation: 584
I have coded a Xamarin Forms mobile app and a webservice which has started to fail as the initial Activity is loading. (This is all in Visual Studio, with the webservice and the MyAppName.Android projects set as the startup projects.) Visual Studio is uptodate and the Android app targets Android 11. I am running Windows 11 Enterprise.
The mobile app displays a white screen and hangs when loading the first Activity. Oddly this same code runs fine on another developer's PC (Windows 10) and my laptop (Windows 11 Pro).
The two exceptions occur about equally often.
This one throws in file: NetworkStream.cs, a locked file.
System.ObjectDisposedException: 'Cannot access a disposed object. Object name: System.Net.Sockets.NetworkStream'.'
This one throws in the Sockets.cs file - another locked file
System.IO.IOException: "Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request."
And the Inner Exception for that one is:
SocketException: The I/O operation has been aborted because of either a thread exit or an application request.
It started to seem that breakpoints were affecting my results so I am using Debugger.Log() to track the code. LoginPage.xaml.cs is the first Activity. At the top of the constructor I have this:
Debugger.Log(0, "LoginPage", "pds Before InitializeComponent");
InitializeComponent();
Debugger.Log(0, "LoginPage", "pds After InitializeComponent");
The first Debugger line writes to the Output window fine. The line after InitializeComponent almost never gets written. Even if that second Debugger line gets written. I still get the same results.
The xaml for that has this at the top:
<ContentPage.BindingContext>
<local:LoginViewModel/>
</ContentPage.BindingContext>
And the constructor for LoginViewModel writes all the Debugger messages I have in that. But after that constructor runs, the mobile app never moves off the white screen it displayed and after about 50 seconds one of the exceptions throws.
Before the exception throws Visual Studio always writes something like this to the Output window.
The thread 3 has exited with code 0 (0x0).
But from what I read these outputs can be ignored. Still it seems to me that Visual Studio is doing something that disposes of an object or breaks the connection. Ideas?
Upvotes: 1
Views: 84
Reputation: 584
In Visual Studio > Exceptions Settings, I had the Break on Common Language Runtime Exceptions check box checked. I unchecked it and all runs fine.
Part of the break through was figuring out that the exceptions were coming from the development web service. We had started the ws and were talking about what to do next and one of the exceptions threw after about 1 minute and 20 seconds.
I guess another tell tale sign was that the files that threw were clearly locked - displaying a lock next to the file name.
Upvotes: 1