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

VS 15.5 Mono Linker throws NullReferenceException when trying to link on Xamarin.Andoird #270

Closed
PureWeen opened this issue Dec 5, 2017 · 6 comments
Assignees
Labels
bug Something isn't working.

Comments

@PureWeen
Copy link

PureWeen commented Dec 5, 2017

AzureDeviceClient.zip

Windows 10 and iOS

I'm using the latest 1.6.0 but the same issues exists with 1.5.2

Description of the issue:

Compiling Xamarin android with full linking on causes the following exception

Severity Code Description Project File Line Suppression State
Error The "LinkAssemblies" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
at Mono.Linker.TypeReferenceExtensions.d__4.MoveNext()
at Mono.Linker.Steps.TypeMapStep.TryMatchMethod(TypeReference type, MethodDefinition method)
at Mono.Linker.Steps.TypeMapStep.d__12.MoveNext()
at Mono.Linker.Steps.TypeMapStep.MapVirtualInterfaceMethod(MethodDefinition method)
at Mono.Linker.Steps.TypeMapStep.MapVirtualMethods(TypeDefinition type)
at Mono.Linker.Steps.TypeMapStep.MapType(TypeDefinition type)
at Mono.Linker.Steps.TypeMapStep.ProcessAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1696

Code sample exhibiting the issue:

I've attached a project that's just an empty Android project I added the IoT libraries to that should exhibit the issues

@PureWeen
Copy link
Author

PureWeen commented Dec 5, 2017

I tried stepping through it a little bit with windbg and it seems like it chokes on BufferedInputStream when it's trying to match up properties with interfaces

https://github.com/mono/linker/blob/e4dfcf006b0705aba6b204aab2d603b781c5fc44/linker/Mono.Linker.Steps/TypeMapStep.cs#L158

seems to return a null value that gets passed into

TryMatchMethod 

@PureWeen
Copy link
Author

PureWeen commented Dec 6, 2017

It seems like these being netstandard1.3 + the ICloneable fake out in AMQP + me using netstandard2.0 = Not Happy Linker

I pulled down this and the AMQP project and just changed the Netstandard libraries over to 2.0 and removed ICloneable from the NETSTANDARD typedef since ICloneable is part of the Netstandard2.0 spec

I also had to do this
dotnet/efcore#8922
(Highlighting that I needed to add version 4.3.0 of the Unsafe nuget.)
and added this into my linker.xml file

  <assembly fullname="Microsoft.Azure.Amqp">
    <type fullname="System.Collections.Generic.KeyedByTypeCollection`1">
      <method name=".ctor" />
    </type>
    <type fullname="System.Collections.Generic.KeyedByTypeCollection`1" />
    <type fullname="*" />
  </assembly>

Now my Android project is able to compile and run and IoT messages are happily working

@CIPop CIPop added bug Something isn't working. help wanted Extra attention is needed. labels Dec 7, 2017
@CIPop
Copy link
Member

CIPop commented Dec 7, 2017

Thanks @PureWeen for reporting the issue and the solution!
I'd need more time to understand why we need ICloneable in NetStandard. If we can remove it, this should fix the netstandard1.3 build. If not, we can at least build netstandard2.0 as well for Android support.

@tameraw @jasmineymlo

@CIPop
Copy link
Member

CIPop commented Feb 7, 2018

Thanks again @PureWeen for researching and finding a workaround. I was going through the issues linked and found a few Xamarin/Android issues that are tracking a bug-fix on their side:

dotnet/android#1196 (comment)
Appears as the root bug is: dotnet/android#1154

A group of related to bugs is also documented here: xamarin/AndroidSupportComponents#75 (comment)

@CIPop CIPop removed the help wanted Extra attention is needed. label Feb 7, 2018
@abhipsaMisra
Copy link
Member

@PureWeen : Could you please try again with the latest Visual Studio version? According to Xamarin issue #1196, updating to latest version should work. We have also added a readme and some samples to our repository. Please let us know if that helps.

@abhipsaMisra abhipsaMisra self-assigned this May 29, 2018
@CIPop
Copy link
Member

CIPop commented Jun 11, 2018

Thanks @abhipsaMisra for the investigation and new sample!
Xamarin appears to have released a new version fixing the linker problem.

Closing for now: please reopen if this is still observed on the latest Visual Studio release.

@CIPop CIPop closed this as completed Jun 11, 2018
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

3 participants