Xamarin-android: await within method with returntype Task<T> makes app crash

Created on 24 Mar 2018  Â·  9Comments  Â·  Source: xamarin/xamarin-android

Steps to Reproduce

  1. Open attached project
  2. Run attached project
  3. Debug through the App.Foo method. Task.Delay will make the app crashing without any error. In fact any await will make the app crash.
  4. Just noticed: The error seems only to occur when debugging through the program (when just running the app, it shows the MainView).
  5. Notice if you change the signature of method Foo to Task<bool> Foo<TResponse>() the app works correctly.

BugApp1.zip

Expected Behavior

Delay the thread by 500 ms.

Actual Behavior

Crashes without any Exception. Log shows the following error message (hopefully I've picked the right one - check it yourself):
03-24 21:44:15.602 F/ ( 4720): /Users/builder/jenkins/workspace/xamarin-android-d15-6/xamarin-android/external/mono/mono/mini/debugger-agent.c:4846: (null) assembly:mscorlib.dll type:BadImageFormatException member:<none>

Version Information


Visual Studio version:

Microsoft Visual Studio Community 2017 
Version 15.6.4
VisualStudio.15.Release/15.6.4+27428.2015
Microsoft .NET Framework
Version 4.7.02556

Installierte Version: Community

Visual F# Tools 10.1 für F# 4.1   00369-60000-00001-AA480
Microsoft Visual F# Tools 10.1 für F# 4.1

Allgemeine Azure-Tools   1.10
Bietet allgemeine Dienste für die Verwendung durch Azure Mobile Services und Microsoft Azure-Tools.

Application Insights-Tools für Visual Studio-Paket   8.11.10212.1
Application Insights-Tools für Visual Studio

ASP.NET and Web Tools 2017   15.0.40314.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   1.0
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.51214.0
Zusätzliche Informationen finden Sie unter https://www.asp.net/.

Azure App Service Tools v3.0.0   15.0.40215.0
Azure App Service Tools v3.0.0

C#-Tools   2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
C#-Komponenten, die in der IDE verwendet werden. Je nach Projekttyp und Einstellungen kann eine andere Compilerversion verwendet werden.

Color Picker   1.0
Integrated Color Picker for Visual Studio IDE and Editor

EditorConfig Language Service   1.17.237
Language service for .editorconfig files.

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.

GorillaPlayerPackage Extension   1.0
GorillaPlayerPackage Visual Studio Extension Detailed Info

JavaScript-Sprachdienst   2.0
JavaScript-Sprachdienst

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

Microsoft Azure-Tools   2.9
Microsoft Azure-Tools für Microsoft Visual Studio 2017 – v2.9.51212.2

Microsoft Continuous Delivery-Tools für Visual Studio   0.3
Die Konfiguration der fortlaufenden Buildintegration und der fortlaufenden Buildbereitstellung innerhalb der Visual Studio-IDE wird vereinfacht.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio   4.9.11-pre (71eb098)
Support for debugging Mono processes with Visual Studio.

NuGet-Paket-Manager   4.6.0
NuGet-Paket-Manager in Visual Studio. Weitere Informationen zu NuGet finden Sie unter "http://docs.nuget.org/".

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   15.1.61801.210
Microsoft SQL Server Data Tools

TypeScript-Tools   15.6.20202.3
TypeScript-Tools für Microsoft Visual Studio

Visual Basic-Tools   2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80
Visual Basic-Komponenten, die in der IDE verwendet werden. Je nach Projekttyp und Einstellungen kann eine andere Version des Compilers verwendet werden.

Visual Studio Code-Debugadapter-Hostpaket   1.0
Interopebene zum Hosten der Visual Studio Code-Adapter in Visual Studio

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSColorOutput   2.5.1
Color output for build and debug windows - http://mike-ward.net/vscoloroutput

Xamarin   4.9.0.752 (0faa808ee)
Visual Studio-Erweiterung, um Entwicklung für Xamarin.iOS und Xamarin.Android zu ermöglichen.

Xamarin Designer   4.10.58 (cee1369d0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK   8.2.0.16 (HEAD/a78295902)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   11.8.1.28 (3979d08)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

logfile.txt

Most helpful comment

This is fixed with using .GetAwaiter() instead of await

All 9 comments

Any solution? I am having same problem and i am stuck with this for almost one week!

The error appear only when debugging on first line of this async,
If running app without breakpoints, nothing happed but also no data comes from Uri.

public async Task<T> GetAsync<T>(string relativeUri, JsonConverter specificConverter = null) { HttpResponseMessage response = await httpClient.GetAsync(relativeUri); response.EnsureSuccessStatusCode(); }

This is fixed with using .GetAwaiter() instead of await

Any update regarding the issue. How can we get it fixed without any workaround.

I also had to use the workaround. Even when wrapped in a try catch the application just terminates it doesn't handle any exceptions at all.

I had to use ConfigureAwait(false).GetAwaiter().GetResult()

I just encountered the same bug.
await _httpClient.GetAsync()

If I step through the code the application dies. If I set a breakpoint after the line where I do the call its fine. Alternatively GetAwaiter().GetResult() also works.

This happens not just on Andriod but on iOS too.

Any news about this one, I am using the workaround but I would really like to have all my code consistent :(

Upvote

Seems it got fixed with https://github.com/mono/mono/issues/17569 (but probably hasn't shipped yet).

Was this page helpful?
0 / 5 - 0 ratings