Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Build error on UWP form ARM 32 with an external dll and an async function

Discussion in 'Windows' started by raggnic, Mar 21, 2023.

  1. raggnic

    raggnic

    Joined:
    Sep 27, 2017
    Posts:
    13
    Hello

    We have an issue when building for UWP - ARM32 (Hololens2)
    We have a dll with async functions like this:
    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Net.Http;
    5. using System.Runtime.InteropServices;
    6. using System.Text;
    7. using System.Text.RegularExpressions;
    8. using System.Threading.Tasks;
    9.  
    10. namespace TestClassLib
    11. {
    12.     public class TestClass1
    13.     {
    14.         private readonly HttpClient _httpClient = new HttpClient();
    15.  
    16.      
    17.         public async Task<int> GetDotNetCountAsync()
    18.         {
    19.             // Suspends GetDotNetCount() to allow the caller (the web server)
    20.             // to accept another request, rather than blocking on this one.
    21.             var html = await _httpClient.GetStringAsync("https://dotnetfoundation.org");
    22.  
    23.             return Regex.Matches(html, @"\.NET").Count;
    24.         }
    25.  
    26.         public int GetDotNetCount()
    27.         {
    28.          
    29.  
    30.             return GetDotNetCountAsync().Result;
    31.         }
    32.  
    33.  
    34.     }
    35. }
    36.  
    It's compiled for ARM 32/Release. In an unity script if we call the synchrone function everythings works, but if we await on the async function over the dll boundary the build breaks.
    Code (csharp):
    1.  
    2. #if UNITY_WSA && !UNITY_EDITOR
    3. TestClass1 t = new TestClass1();
    4. int n = t.GetDotNetCount(); //this works
    5.  
    6. int n2 = await t.GetDotNetCountAsync(); //this breaks the build
    7. #endif
    8.  
    Build error is error CS1705: Assembly 'ClassLib' with identity 'ClassLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Any clue would be welcome. Thanks for reading
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    Looks like your precompiled ClassLib is compiled against wrong version of .NET. You should compiling against .NET Standard 2.0 or .NET Standard 2.1 if you want to use it in Unity.