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

Using Microsoft.Azure.Devices.Client in Xamarin.Forms Android project #434

Closed
damir-bajramovic opened this issue Mar 29, 2018 · 8 comments
Closed
Assignees
Labels
bug Something isn't working.

Comments

@damir-bajramovic
Copy link

damir-bajramovic commented Mar 29, 2018

I made a Xamarin.Forms project. .NET Standard is the code sharing strategy. Using Visual Studio, Windows 10.

I am able to send messages to the IoT Hub on the UWP app, but not from Android. Build succeeds, but it doesn't deploy right on the device.

Description of the issue:

I installed 1.7.0 version of Microsoft.Azure.Devices.Client NuGet package.

Code sample exhibiting the issue:

public class IoT
{
    public IoT(string connectionString)
    {
        _deviceClient = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
    }
    private DeviceClient _deviceClient;

    public async Task SendMessage(object data)
    {
        try
        {
            Message message = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data)));
            if (_deviceClient != null)
            {
                await _deviceClient.SendEventAsync(message);
            }
            else Debug.WriteLine("Message failed to send" + JsonConvert.SerializeObject(data));
        }
        catch
        {
            Debug.WriteLine("EXCEPTION!");
        }
    }
}

}

These are some of the entries when I build the project:

Ignoring C:\Users\User.nuget\packages\system.runtime.compilerservices.unsafe\4.4.0\ref

And after the deployment fails I see this:

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

How to resolve this issue? Is it even possible to use Microsoft.Azure.Devices.Client for Android devices?

I tried various linker options but to no avail.

Issue sample repo

Check out the repo with the sample code: https://github.com/ChakraSpice/Xamarin-IoT-Android-Issue-Sample (use your own connection string)

@craylward
Copy link

craylward commented Mar 29, 2018

This is a known Xamarin.Android issue: dotnet/android#1162

Also listed as an issue in this repo: #373

Try replacing the contents of
USER\.nuget\packages\system.runtime.compilerservices.unsafe\4.4.0\ref with contents of USER\.nuget\packages\system.runtime.compilerservices.unsafe\4.4.0\lib

@damir-bajramovic
Copy link
Author

I tried that, and that doesn't work.

@CIPop
Copy link
Member

CIPop commented Apr 3, 2018

Thanks @craylward and @ChakraSpice . We are aware of several Xamarin issues and we will need to spend more time investigating.

@CIPop CIPop added the bug Something isn't working. label Apr 3, 2018
@abhipsaMisra
Copy link
Member

We have updated some Xamarin Android samples in our repository which implement send & receive messages. Could you please try with those and let us know if it helps! Thanks!

@abhipsaMisra
Copy link
Member

@ChakraSpice - Could you please try out using the latest samples and let us know if that helps. In case you face further issues, please open another GitHub issue. Thanks!

@abhipsaMisra abhipsaMisra self-assigned this May 23, 2018
@nimanasr
Copy link

nimanasr commented Jul 9, 2018

I have the same issue when trying to deploy the application on Android emulator. I tried your samples but I get the old error message. Which sample do you exactly mean?

@abhipsaMisra
Copy link
Member

@nimanasr - The Xamarin Android issue which was causing this error has since been resolved. Please make sure that you have the latest versions of the entire tool-chain installed; and you can refer to the samples present here. Please let us know if that helps. Thanks!

@nimanasr
Copy link

@abhipsaMisra the issue is resolved after upgrading Visual Studio 2017 to version 15.7.5. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

5 participants