Search Unity

Bug Hololens 2 and WCF Client

Discussion in 'AR' started by WeirdAnakin, Dec 16, 2020.

  1. WeirdAnakin

    WeirdAnakin

    Joined:
    Dec 16, 2020
    Posts:
    1
    Hi,

    we recently started to port our existing Hololens 1 application to the Hololens 2 and are facing various challenges on the way. Almost all of them are related to IL2CPP in combination with mandatory 3rd party libraries we have to use.
    One of them is consuming WCF WebServices and while it's working fine in the editor/player, we just can't get it to work through the IL2CPP deployment on the real device. It all seems to come down to System.Servicemodel and its dependencies and after days of try and error, we still haven't found a way to make it work. Here's what we've tried so far:

    First attempt
    • Add the System.ServiceModel.Primitives nuget to unity
    • Add the following references to csc.rsp:
    -r:System.ServiceModel.dll
    -r:System.ServiceModel.Duplex.dll
    -r:System.ServiceModel.NetTcp.dll
    -r:System.ServiceModel.Primitives.dll
    -r:System.ServiceModel.Security.dll
    -r:System.ServiceModel.http.dll​

    UnityEditor: compiles and connects successfully to the Webservices.
    IL2CPP: compiles and deploys successfully, but once the first instance of e.g BasicHttpBinding is created in code, it throws a ProfileException
    >> in the C++ code we see that it's throwing this purposefully right in the constructor of the class (il2cpp_codegen_raise_profile_exception)

    Second attempt
    • Keep the nugets and csc.rsp as above
    • Additionally drop System.ServiceModel.dll and System.IdentityModel.dll from Unity\Hub\Editor\2019.4.14f1\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api into the Assets folder
    UnityEditor: compiles and connects successfully to the Webservices.
    IL2CPP: compiles and deploys successfully; instance of BasicHttpBinding is successfully created, but then fails on first access of ClientBase<>.Endpoint, triggered through the construction of System.ServiceModel.EndpointAddress, with a NullReferenceException
    >> in the C++ code we see that the constructor of BasicHttpBinding is now generated fine, but that it purposefully throws the null exception in the getter of the mentioned property (il2cpp_codegen_raise_null_reference_exception)

    Third attempt:
    we then basically tried to drop various implementations of System.ServiceModel in the assets folder, from MonoBleeding sub directories, but only with different errors and no success so far. Depending on the used versions, we either get errors already in the Editor, due to missing references, or later on compilation errors in C++ due to wrongly generated code.

    Conclusion:
    We're really stuck now. Searching the web up and down didn't help and Try and error is extremely time-consuming since we always have to make a full compilation roundtrip, to either inspect the C++ code to see if the generated code has changed, or deploy to the device to see if it crashes at runtime.

    So the question is, are there any best practices to make WCF work on Hololens 2? Our assumption would have been it should work, since it works nicely in the editor. So the question might need to be rephrased to:

    Is there any best practice to make WCF work through IL2CPP?

    Any help would be greatly appreciated!
     
    Last edited: Dec 16, 2020
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Please file a bug report and reply here with the issue tracker id.