Search Unity

Unable to use uwp plugin windows minimum version 16299

Discussion in 'Windows' started by FTGXR10, Sep 18, 2020.

  1. FTGXR10

    FTGXR10

    Joined:
    Nov 27, 2019
    Posts:
    7
    Unity version# 2019.4.8f1

    We have a need to use a c# UWP dll with windows minimum target set as 16299 and use the type that derives from the System.IO.Stream type. There are two issues with this. Firstly, while copying the plugin within Unity, got the error as below. I believe this error is due to the System.IO.Stream type which is moved to System.Runtime.dll for windows build#16299. For lower windows builds, this type is present in System.IO.dll itself and has no issues. Only starting from 16299 build, this error throws.

    DllCompileError.png

    I just ignored this error and tried building the project in Unity for UWP platform. Then I got the error as attached below. It throws up the System.Runtime error and unable to build the project. I tried setting the API Compatibility Level to both .Net 4.x and .net standard 2.0, but no luck.
    Can you let me know how to use a uwp plugin with 16299 min version?

    I've also created the bug # 1277945.

    BuildError.png
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    What you're trying to do is not supported.

    On .NET scripting backend we only support C# plugins that target "Microsoft.NETCore.UniversalWindowsPlatform": "5.4.4" or older. When building the project, you have to check the .csproj file for this entry:

    Code (csharp):
    1. <ItemGroup>
    2.     <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
    3.       <Version>5.4.4</Version>
    4.     </PackageReference>
    5.   </ItemGroup>
    And make sure that the version isn't newer.

    On IL2CPP scripting backend, you should build the DLL just as .NET Standard 2.0, rather than targeting a specific UWP .NET Core version. You can add UWP related extensions to it as references afterwards.
     
    FTGXR10 likes this.
  3. FTGXR10

    FTGXR10

    Joined:
    Nov 27, 2019
    Posts:
    7
    There's one catch - we are unable to set this target to 5.4.4 as we're using .NET standard 2.0 dll reference to this uwp plugin. And it's not just one dll, there are many bunch of .net standard 2.0 dll's are been referred by this UWP plugin and the versions cannot be lowered.

    What could be the way forward for this problem?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Switch to IL2CPP scripting backend. .NET Standard 2.0 DLLs are just not supported on .NET scripting backend and will never work.
     
  5. FTGXR10

    FTGXR10

    Joined:
    Nov 27, 2019
    Posts:
    7
    We're already using IL2CPP backend as using Unity 2019.4. The actual problem I'm mentioning is, we have third party uwp DLLs that in turn use UWP target version 6.x because that plugin uses other .net standard 2.0 DLLs.

    We've no source access to uwp plugin as it's external.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Can you ask them to recompile the DLL as .NET standard 2.0? The issue is that it's targeting System.Runtime and friends that are newer than in .NET Standard 2.0 and thus don't work in Unity.
     
  7. FTGXR10

    FTGXR10

    Joined:
    Nov 27, 2019
    Posts:
    7
    Not possible to compile as .net standard 2.0 because it requires uwp functionalities and it's quite big application which interfaces with hardware.

    And we're developing application for hololens2, so we need to refer those hardware interfacing functionalities to use it in hololens2.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    It can be compiled as .NET Standard 2.0 with additional references to those UWP APIs.
     
  9. ragbabutr

    ragbabutr

    Joined:
    Aug 18, 2021
    Posts:
    4
    Hi @Tautvydas-Zilys

    Is there a way to call UWP API from .NET Standard 2.0 library? I tried the following code in a class library project but does not seem to work. Unable to resolve type EasClientDeviceInformation. Following are the project details:

    .csproj
    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
    <Version>5.4.4</Version>
    </PackageReference>
    </ItemGroup>
    </Project>

    Class1.cs
    using System;
    namespace ClassLibrary1
    {
    public class Class1
    {
    void test()
    {
    var easClientDeviceInformation = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
    }
    }
    }
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Add a reference to Windows.winmd. It can be found inside Windows SDK under "C:\Program Files (x86)\Windows Kits\10\UnionMetadata\<SDK_VERSION>\Windows.winmd".

    You also don't need that PackageReference.
     
  11. ragbabutr

    ragbabutr

    Joined:
    Aug 18, 2021
    Posts:
    4
    Referring the winmd, made the solution to compile.

    But now the issue with referring that compiled assembly back to Unity (2019.4.22f1). I'm getting the following error while building the UWP player. I've copied both dll & winmd into assets folder. Checked with API scripting compatibility set to both .NET 4.x or .NET Standard 2.0. The same issue occurs. Any addition settings or files need to be copied to made it work?

    Assets\Test.cs(9,20): error CS7069: Reference to type 'EasClientDeviceInformation' claims it is defined in 'Windows.Security.ExchangeActiveSyncProvisioning.EasContract', but it could not be found

    Test.cs:

    using UnityEngine;

    public class Test : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {
    #if ENABLE_WINMD_SUPPORT
    var info = TestLib.UwpHelper.GetDeviceInfo();
    Debug.Log(info);
    #endif
    }
    }
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    How did you configure the .dll and the .winmd file in the plugin inspector? Which exact windows.winmd did you reference in your C# project?
     
  13. ragbabutr

    ragbabutr

    Joined:
    Aug 18, 2021
    Posts:
    4
    Copied from here: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.18362.0\Windows.winmd as it's the same reference which is given in the class library plugin.

    Attached screenshot of plugin inspectors for both dll & winmd files

    ClassLibrary1-Inspector.png WindowsWINMD-Inspector.png
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Oh, you don't need to copy Windows.winmd to your project, that is probably causing a conflict. Unity will automatically reference it from Windows SDK when you build for UWP. You just need to reference it yourself when building assemblies outside of Unity.
     
  15. ragbabutr

    ragbabutr

    Joined:
    Aug 18, 2021
    Posts:
    4
    The error is still the same with/without the Windows.winmd file. Attached the projects for reference. Let me know if I'm missing anything please.
     

    Attached Files:

  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Looks like you found a bug in Windows SDK! Windows.winmd claims that particular type is in Windows.Security.ExchangeActiveSyncProvisioning.EasContract.winmd, but it's actually in Windows.Foundation.UniversalApiContract.winmd. I was able to workaround it by adding a reference to Windows.Foundation.UniversalApiContract.winmd directly in the project file:

    Code (csharp):
    1. <Project Sdk="Microsoft.NET.Sdk">
    2.  
    3.   <PropertyGroup>
    4.     <TargetFramework>netstandard2.0</TargetFramework>
    5.   </PropertyGroup>
    6.  
    7.   <ItemGroup>
    8.     <Reference Include="C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd"/>
    9.   </ItemGroup>
    10.  
    11. </Project>
     
    ragbabutr likes this.