Search Unity

Understanding Unity Api Compatibilty

Discussion in 'Scripting' started by stonstad, Apr 9, 2019.

  1. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    I have code which works in the editor... but fails at runtime with an IL2CPP/.NET 4.x build. I'm getting NotSupportedException for code that is implemented in Mono: https://github.com/mono/mono/blob/m...Model/System/ServiceModel/BasicHttpBinding.cs and otherwise works in the editor.

    Code (CSharp):
    1. System.NotSupportedException: System.ServiceModel.BasicHttpBinding::.ctor
    2.   at System.ServiceModel.BasicHttpBinding..ctor (System.ServiceModel.BasicHttpSecurityMode securityMode) [0x00000] in <00000000000000000000000000000000>:0
    My question is -- how do I know ahead of time what is supported by Unity's version of Mono/.NET and what isn't? Or is this a bug?

    Thanks,
    Shaun
     
    Last edited: Apr 9, 2019
  2. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Further adding to the strangeness, it would seem that this works in the Unity editor because its version of Mono does indeed have the class implementation. It's only the IL2CPP build output that does not have the class implemented. How do I understand when this will happen? i.e. how can I know ahead of time what IL2CPP will or won't support -- assuming that this class implementation should be missing at build output runtime?

     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Did you switch to 4.x in the player options?

    I dont know if its defualt by now, im on 2017.4
     
  4. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    Yep.

     
  5. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    I'm using Unity 2018.3.12f1.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,935
    The short answer is that we don't have a good way to determine what is supported or not supported in the class library code on various platforms. There are two different axes on which would could have support or not:
    1. JIT vs. AOT (i.e. Mono vs. IL2CPP) - there are some parts of the class libraries that don't work well with AOT runtimes.
    2. Platforms - for example, some platforms don't support IPv6, or threads, or networking, etc.
    At the moment we don't have documentation about what is supported on each platform, which is not great. In this case, please drop us a bug report, we might be able to support this with IL2CPP. At least, we can have a look at it.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,935
    Also, note that the Api Compatibility Level option sets the C# compile-time profile. That option does not impact the actual implementation of the class libraries used, as that implementation may vary based on either (1) or (2) I mentioned above.

    If you want more errors about unsupported APIs at compile time, I would use the .NET Standard 2.0 Api Compatibility Level. That is a smaller profile than .NET 4.x Equivalent, and it will have a better chance of being supported. There is a good bit of .NET 4.x Equivalent that we cannot support on all platforms, so you will get more errors at runtime with it.

    This really comes down to when you want to see the errors.
    • Compile time - use .NET Standard 2.0
    • Run time - use .NET 4.x Equivalent
     
  8. stonstad

    stonstad

    Joined:
    Jan 19, 2018
    Posts:
    659
    @JoshPeterson Thanks, Josh. I filed a report and I'm hopeful they might consider adding this class to the player runtime. It's likely my last blocker before migrating from the .NET scripting backend to IL2CPP. To be honest, I'm surprised it is not present. Without this class no web services will work in IL2CPP. And then if that's the case, why support System.ServiceModel.dll at all...
     
  9. borodai

    borodai

    Joined:
    Jul 18, 2019
    Posts:
    13
    This is exactly my problem and my question as well. System.ServiceModel.dll is not supported with il2cpp and how would I know this before wasting weeks trying to get il2cpp to work?

    I am paying for professional license, and I am not sure what it gives me short of removing the watermark, so at least having some documentation of what is supported would be really useful, just out of courtesy.
     
    Last edited: Apr 28, 2020