Linker - Please lift the magic

When switching on "Link all assemblies" we get following nice stack trace when running our app. Which is okay, because thats what xamarin warns one about. But how are you supposed to find out what exactly the linker removed and whats missing?

RebuyApp.Common.Services.GreenSearchService.SearchAsync () in /Users/otamares/Documents/development/rebuy/universal-app/RebuyApp/Common/Services/GreenSearchService.cs:31
System.Threading.Tasks.SynchronizationContextContinuation.Execute () in 
System.Threading.Tasks.Task.ProcessCompleteDelegates () in 
System.Threading.Tasks.Task.HandleGenericException (e=Count = 1) in 
System.Threading.Tasks.Task.TrySetException (aggregate=Count = 1, cancellation=false, observed=true) in 
System.Runtime.CompilerServices.AsyncTaskMethodBuilder<RebuySdk.Common.PageResult<RebuySdk.SearchClient.Response.SearchResult>>.SetException (exception={System.ArgumentNullException: Argument cannot be null.
Parameter name: method
  at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull (System.Object value, System.String parameterName) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Utilities.ExpressionReflectionDelegateFactory.CreateParametrizedConstructor (System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonArrayContract.CreateWrapper (System.Object list) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewList (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonArrayContract contract, System.Boolean& createdFromNonDefaultCreator) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.Object existingValue, System.String id) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00000] in <filename unknown>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00000] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter`1[RebuySdk.Common.PageResult`1[RebuySdk.SearchClient.Response.SearchResult]].GetResult () [0x00000] in <filename unknown>:0 
  at RebuyApp.Common.Services.GreenSearchService+<SearchAsync>c__async0.MoveNext () [0x000f5] in /Users/otamares/Documents/development/rebuy/universal-app/RebuyApp/Common/Services/GreenSearchService.cs:27 }) in 
Flurl.Http.ResponseMessageExtensions.<ReceiveJson>d__0<RebuySdk.Common.PageResult<RebuySdk.SearchClient.Response.ReceiveJson () in c:\Aldenteware\Flurl\code\Flurl.Http.Shared\ResponseMessageExtensions.cs:22
Microsoft.Runtime.CompilerServices.TaskAwaiter. (state=) in 
Android.App.SyncContext.Post.AnonymousMethod__0 (Parameters=) in 
Java.Lang.Thread.RunnableImplementor.Run (Parameters=) in 
Java.Lang.IRunnableInvoker.n_Run (Parameters=) in 
object.1b952d5d-a0be-4403-98c9-87f1aa15a48b (Parameters=) in 

I used a bit of google foo and mixed with my knowledge i found out that following link description configuration fixes the problem. Why the Linq Create method is an issue here, i have no clue.

<?xml version="1.0" encoding="UTF-8"?>
<linker>
    <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Expression`1">
            <method name="Create" />
        </type>
    </assembly>
    <assembly fullname="Newtonsoft.Json">
        <type fullname="Newtonsoft.Json.Utilities.*" />
    </assembly>
</linker>

Unfortunately i am not able to pin down the exact method and member of Newtonsoft.Json that causes the issue. And even if i could, the linker documentation is so sparse you need to guesstimate what settings could be right :(

It would be nice if someone or xamarin could provide some deeper knowledge regarding the linker, how to find the exact removed culprit and how to fix that.

Posts

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    One simple, but not best, way is to exclude entire problematic assembly out of linking.

  • OtaMaresOtaMares DEMember ✭✭

    Yes, thats what i am doing using the linker description xml but its more the blunt approach. I would great if we could isolate the specific method call to configure the linker accordingly. But no one knows how to do that :)

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    I agree. Perhaps linker could output what was trimmed and from where.

  • OtaMaresOtaMares DEMember ✭✭

    Just a small heads up. When using the configuration as shown in the image and setting the linker to "Link all assemblies", the "Application Output" windows tells you what method in which assembly is missing. With that information it is possible to update the linker description file accordingly.

    image

    A quick example.

    Message: [] Missing method System.PlatformNotSupportedException::.ctor(string) in assembly mscorlib.dll, referenced in assembly /mnt/sdcard/Android/data/de.rebuy.android/files/.__override__/AutoMapper.dll

    mscorlib beeing the assembly. System.PlatformNotSupportedException the type/class and .ctor (note the dot) obviously the method.

    And the resulting linker description xml.

    <assembly fullname="mscorlib">
        <type fullname="System.PlatformNotSupportedException">
            <method name=".ctor" />
        </type>
    </assembly>
    

    Its a bit tedious because you have to go one by one, but at least something.

  • OtaMaresOtaMares DEMember ✭✭

    Hmm doesn't seem to work always. From time to time you only get an exception trace. :\

Sign In or Register to comment.