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

Linker issues when using with Xamarin Android project #197

Closed
PureWeen opened this issue Oct 19, 2017 · 20 comments
Closed

Linker issues when using with Xamarin Android project #197

PureWeen opened this issue Oct 19, 2017 · 20 comments
Assignees
Labels
bug Something isn't working.

Comments

@PureWeen
Copy link

I'm not sure if this is an issue with these libraries, myself, or Xamarin tooling

But I'm getting errors like this when trying to use Microsoft.Azure.Devices.Client with a PackageReference based Xamarin.Android project

Severity	Code	Description	Project	File	Line	Suppression State
Error		The "LinkAssemblies" task failed unexpectedly.
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.ICloneable' (defined in assembly 'Microsoft.Azure.Devices.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35') with scope 'Microsoft.Azure.Amqp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.ICloneable

I've also seen this


Severity	Code	Description	Project	File	Line	Suppression State
Error		The "LinkAssemblies" task failed unexpectedly.
Mono.Linker.MarkException: Error processing method: 'System.Void Microsoft.Azure.Devices.Client.SerializationUtilities::.cctor()' in assembly: 'Microsoft.Azure.Devices.Client.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.ICloneable

I have a reproduction of the issue here
https://github.com/PureWeen/ReactiveUiEvents/tree/linkerproblem

just grab the linkerproblem branch and you'll hopefully see the issue

I'm using VS 15.4 on Windows

@CIPop CIPop added the investigation-required Requires further investigation to root cause this. label Oct 19, 2017
@CIPop
Copy link
Member

CIPop commented Oct 19, 2017

@ryan-z-johnson was looking at similar issues yesterday. One idea that we have about this is that the PCL library may interfere and so I will be removing it part of the next release (see #138 ).
Instead of importing the Devices.Client directly, could you try creating a netstandard lib and import it there? You can then reference the lib from Xamarin and hopefully it'll fix the issue.

@PureWeen
Copy link
Author

Yea that's kind of how I was able to fix it. Basically what I did to fix for now is

  • create netstandard1.2 with fallback since this project is netstandard1.3
  <PropertyGroup>
    <TargetFramework>netstandard1.2</TargetFramework>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10;</PackageTargetFallback>
  </PropertyGroup>
  • then I added that project directly into the platform project. At this point the Android project complains about not being able to find the two "PCL" dlls... So I just added a hard reference to those PCLs into the Android project

And now everything seems to be running

@CIPop
Copy link
Member

CIPop commented Oct 19, 2017

Thanks for the confirmation @PureWeen !
In that case, I'll mark this as a duplicate of #138 .

@CIPop CIPop closed this as completed Oct 19, 2017
@CIPop
Copy link
Member

CIPop commented Oct 24, 2017

After removing PCL, this is still failing. More investigation is required to understand why the Xamarin compiler is throwing this error. The ICloneable appears to be type-forwarded by one of the libraries which causes some conflicts.
I've tried with the latest VS and with a package that doesn't contain any PCL references.

I wasn't able to repro in "Debug" mode.
Since Release is required to deploy applications to the store so this is blocking Android. /cc @tameraw

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018: Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'System.ICloneable' (defined in assembly 'Microsoft.Azure.Devices.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35') with scope 'Microsoft.Azure.Amqp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve System.ICloneable
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.Initialize()
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Mono.Linker.Pipeline.Process(LinkContext context)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    --- End of inner exception stack trace ---
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args) in /Users/builder/data/lanes/4986/fb018c56/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics/Diagnostic.cs:line 163
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Xamarin.Android.Tasks.LinkAssemblies.Execute()
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1577,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

@CIPop CIPop reopened this Oct 24, 2017
@PureWeen
Copy link
Author

By latest VS does that include the Preview builds as well? Talking to one of the Xamarin folks he had told me there were some improvement there to try
/cc @JonDouglas

@CIPop
Copy link
Member

CIPop commented Oct 24, 2017

@PureWeen I didn't try the preview Xamarin build and I'm not yet certain this is a bug on our side or Xamarin. I did successfully test Xamarin/iOS sample and that worked as expected.
If you start a discussion with Xamarin on another GH repo, please add a ref to this link as well.

@CIPop
Copy link
Member

CIPop commented Oct 26, 2017

Tentative workaround from @PureWeen:

In my case it only worked if the netstandard library was 1.2 or lower otherwise I'd get the above exception or the Linker one

  <TargetFramework>netstandard2.0</TargetFramework>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10;</PackageTargetFallback>
  </PropertyGroup>

@CIPop
Copy link
Member

CIPop commented Jan 10, 2018

External issue: Azure/azure-amqp#87

We need to wait for an updated NuGet for AMQP.

@CIPop CIPop removed the investigation-required Requires further investigation to root cause this. label Jan 17, 2018
@CIPop CIPop self-assigned this Jan 23, 2018
@CIPop
Copy link
Member

CIPop commented Feb 7, 2018

@PureWeen I can't repro this anymore after removing PCL (v1.6.1+).

While a new NuGet for Amqp is not yet available, I'm testing a build from their master. I've tried a simpler setup where I've referenced the AMQP 1.3 library then the (locally built) 1.4 and in both cases the Android application built with AOT (Release) without any issues.

Closing for now. Please reopen if you still see this issue with the latest version (1.6.2).

@CIPop CIPop closed this as completed Feb 7, 2018
@PureWeen
Copy link
Author

LinkerProblem.zip

Yea I'm still having the issue with the following verions

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Amqp">
      <Version>2.2.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Azure.Devices.Client">
      <Version>1.6.2</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Azure.Devices.Shared">
      <Version>1.4.1</Version>
    </PackageReference>
  </ItemGroup>

The settings that make the issue come up for me are to set the Linking to
Sdk and User Assemblies
If you just set it to Sdk Assemblies then the error doesn't happen

@TheLever
Copy link

I still have this issue even after selecting "Sdk Assemblies Only". This is with Amqp 2.2.0. Not having the ability to build Release is a huge problem.

@CIPop
Copy link
Member

CIPop commented Mar 16, 2018

Thanks for the notification @TheLever . Reopening this for now until I get some time to resume the Xamarin sample and test infra.

Meanwhile, could you give the latest version a try (1.7.0, etc)? I've removed all PCL #ifdefs and removed the uap10.0 builds in favor of netstandard2.0.

@CIPop CIPop reopened this Mar 16, 2018
@PureWeen
Copy link
Author

it looks like with the latest 15.6 tooling it also gives better error messages when the linker fails.

I installed 1.7.0 and now I am able to compile but unfortunately I keep getting this exception when trying to deploy

Could not load assembly 'System.Configuration.ConfigurationManager' during startup registration.

Still looking around seeing if there's someway to get around this

@PureWeen
Copy link
Author

Which looks like a dependency that was added in version 1.7.0

@iamrmin
Copy link

iamrmin commented May 18, 2018

Did you guys found any solution?

@PureWeen
Copy link
Author

For my ConfigurationManager error I just ended up pulling down the source and recompiling that line of code out
There's a newish 1.7.1 version and some 1.17.0 preview builds though that I haven't tried yet... not sure if those will resolve the issue
@iamrmin have you tried any of the preview nugets by chance?

@abhipsaMisra
Copy link
Member

Hi @PureWeen and @iamrmin : 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

@PureWeen and @iamrmin : The linker problems with Xamarin mentioned here are resolved with the latest Visual Studio update. On setting the Android linking to either 'SDK Assemblies Only' or 'SDK and User Assemblies' and referencing our NuGet packages allows the project to be complied in both Debug and Release mode.
Please feel free to open another GitHub issue and let us know in case the issue persists for you. Thank you!

@PureWeen
Copy link
Author

Awesome!! I'll give this a try next week

@PureWeen
Copy link
Author

Everything looks good
I just removed my custom build of things and went full nuget and it all looks to compile
I also updated everything to the latest 2.1 stuff

Now I just need to wait for app center tooling to catch up :-)

varunpuranik pushed a commit to varunpuranik/azure-iot-sdk-csharp that referenced this issue Dec 13, 2018
…Azure#197)

Scripts to create Debian build containers, scripts to build packages.

Build container packaging has been reworked.

Added README

Debian 8 installs and runs.

some custom contrib files for debian8
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