Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Error in Microsoft.Azure.Devices.Client on Xamarin Android #373

Closed
sgmbh opened this issue Feb 14, 2018 · 14 comments
Closed

Runtime Error in Microsoft.Azure.Devices.Client on Xamarin Android #373

sgmbh opened this issue Feb 14, 2018 · 14 comments
Assignees
Labels
investigation-required Requires further investigation to root cause this.

Comments

@sgmbh
Copy link

sgmbh commented Feb 14, 2018

  • OS and version used: Windows 10
    image

  • SDK version used: Android 8.0

  • Xamarin.Forms version used: 2.5.0.122203 (edit: 2.5.0.280555)

  • Microsoft.Azure.Devices.Client version used: 1.6.2 (edit: 1.7.0)

Description of the issue:

Steps to reproduce the error:
New Cross-Platform App (Xamarin.Forms) > Blank App > Platform (Android & iOS) > UI Technology (Xamarin.Forms) > Code Sharing Strategy (.NET Standard) > OK

On Solution > Manage Nuget Packages for Solution... > Add "Microsoft.Azure.Devices.Client"

Build & run on Android Device (Nexus 5S) with Android 8.0 > it looks like the app will start, but it will crash at startup.

Edit 15. Feb. 2018: Build & run on iOS Device (iPhone 8) with iOS 11 works.

Code sample exhibiting the issue:

see description

Console log of the issue:

Build Log:
buildlog.txt

Smartphone Log:
fulllog.txt

@sgmbh
Copy link
Author

sgmbh commented Feb 15, 2018

I'm not sure if this is the same? It looks like this three problems are somehow related to visual studio for mac?
Perhaps it's something like this? But I'm not sure...
xamarin/xamarin-android#1196
xamarin/xamarin-android#1154
Microsoft/msbuild#2776

@arturl
Copy link
Contributor

arturl commented Feb 19, 2018

I see the same behavior. Merely adding Microsoft.Azure.Devices.Client package v1.6.2 causes the app to crash at startup. The log:

02-18 18:27:45.744 D/Mono    ( 5347): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
02-18 18:27:45.744 F/monodroid-assembly( 5347): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
02-18 18:27:45.744 F/monodroid-assembly( 5347): This might be due to an invalid debug installation.
02-18 18:27:45.744 F/monodroid-assembly( 5347): A common cause is to 'adb install' the app directly instead of doing from the IDE.

@CIPop CIPop added the investigation-required Requires further investigation to root cause this. label Feb 20, 2018
@CIPop CIPop self-assigned this Feb 20, 2018
@benclerix-cegeka
Copy link

Can you give an ETA or workaround on this?

@CIPop
Copy link
Member

CIPop commented Mar 23, 2018

@benclerix-cegeka At the moment this seems to be a Xamarin compiler issue.
We need more time to create a new sample using the latest templates and see if we can somehow work-around the issue. Unfortunately I can't say when that's going to be ready...

@benclerix-cegeka
Copy link

@CIPop Ok thanks for the fast feedback!

@jfversluis
Copy link

A workaround seems to be to set the Linker option to "Sdk and User assemblies" under the Android options in the properties of the Droid project. Not sure what the reason is but the System.Runtime.CompilerServices.Unsafe.dll doesn't seem to be copied to the output folder, maybe other binaries as well.

Copying them manually, packing the APK and deploying it should probably work as well.

@sgmbh
Copy link
Author

sgmbh commented Mar 28, 2018

@jfversluis it looks like it's a workaround for some projects. In my "steps to reproduce"-project the app didn't crash anymore. But in my real app I get now "The LinkAssemblies task failed unexpectedly". I look into that, perhaps I find a fix for that.

@jfversluis
Copy link

@sgmbh it seems to be a trade-off indeed and not working for all projects. I found the same issue in several other places with a couple of workarounds, see the links underneath.

https://developercommunity.visualstudio.com/content/problem/152947/xamarin-android-run-error-could-not-load-assembly.html

dotnet/efcore#8922 (comment)
(scroll down for more possible solutions)

@sgmbh
Copy link
Author

sgmbh commented Mar 29, 2018

Thanks @jfversluis for this links. Actually I tried exactly this steps before because I also saw this error : "System.Runtime.CompilerServices.Unsafe" (third last line in my fulllog file). Although I don't use Entity Framework, it looks like the problem seems related.

@benclerix-cegeka
Copy link

Following solution worked for me: dotnet/android#1196 (comment).

@sgmbh
Copy link
Author

sgmbh commented Mar 29, 2018

@benclerix-cegeka I tried your workaround but unfortunately I get the same error "link assemblies task failed" in a slightly other way:

The "LinkAssemblies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'System.Security.Cryptography.ProtectedData, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Security.Cryptography.ProtectedData.dll'

@cheles
Copy link

cheles commented May 8, 2018

I can confirm that latest vs 15.7 with XF 3.0.0.446417 fixed this issue.

@sgmbh
Copy link
Author

sgmbh commented May 16, 2018

I can also confirm that with the following version this issue is fixed:
Visual Studio 15.7.1
Xamarin.Forms 3.0.0.482510
Microsoft.Azure.Devices.Client 1.7.1

@sgmbh sgmbh closed this as completed May 16, 2018
varunpuranik pushed a commit to varunpuranik/azure-iot-sdk-csharp that referenced this issue Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation-required Requires further investigation to root cause this.
Projects
None yet
Development

No branches or pull requests

7 participants