Code Monkey home page Code Monkey logo

Comments (8)

pirunxi avatar pirunxi commented on July 17, 2024

Because isomorphic method signatures are combined, It's common that you find nothing about async methods.

Do you have use HybridCLR.RuntimeApi.LoadMetadataForAOTAssembly to load 'mscorlib.dll' for patching aot metadata? You can read this article .

make sure you:

  • install latest com.focus-creative-games.hybridclr_unity(version >= 0.8.0) in github
  • install latest hybridclr c++ codes by latest hybridclr_unity
  • use HybridCLR.RuntimeApi.LoadMetadataForAOTAssembly to load 'mscorlib.dll' 。 'mscorlib.dll' must be stripped aot assembly that was generated during building.
  • properly config HybridCLR/Settings
  • run HybridCLR/Generate/All before build.

from hybridclr.

Clancey avatar Clancey commented on July 17, 2024

I have tried following everything, as listed in the doc. I have only slightly modified the project.

I added a new class which I am trying to HotUpdate

public static class AppLoader {
  public static async void Init() {
    await LoadGame();
  }

  static async Task LoadGame() {
    Debug.Log("Load Game Called");
    //Load the Scenes 
    var sceneAb = await LoadDll.GetStreamingAssetBundle("prefabs");
    string[] scenePaths = sceneAb.GetAllScenePaths();
    foreach (var s in scenePaths)
      Debug.Log($"Scene: {s}");
    SceneManager.LoadScene("MyScene");

  }

And I call into it from the LoadDll.cs in the StartGame

    async void StartGame()
    {
        Debug.Log("Start Game Called");
        await LoadMetadataForAOTAssemblies();
        Debug.Log("Loading ASsembly: Assembly-CSharp");
        var gameAss = await GetAssembly("Assembly-CSharp.dll");

        var appType = gameAss.GetType("AppLoader");
        Debug.Log($"AppLoader Loaded: {appType != null}");
        var mainMethod = appType.GetMethod("Init");
        Debug.Log($"Init Method Loaded: {mainMethod != null}");
        mainMethod.Invoke(null, null);
  }
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Start Game Called
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

LoadMetadataForAOTAssembly:mscorlib.dll. ret:OK
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<LoadMetadataForAOTAssemblies>d__13:MoveNext()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

LoadMetadataForAOTAssembly:System.dll. ret:OK
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<LoadMetadataForAOTAssemblies>d__13:MoveNext()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

LoadMetadataForAOTAssembly:System.Core.dll. ret:OK
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<LoadMetadataForAOTAssemblies>d__13:MoveNext()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start(TStateMachine&)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Loading ASsembly: Assembly-CSharp
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

AppLoader Loaded: True
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Init Method Loaded: True
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
<StartGame>d__12:MoveNext()
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(TStateMachine&)
LoadDll:StartGame()
<DownLoadAssets>d__11:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

ExecutionEngineException: NotSupportNative2Managed
  at AppLoader.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll.StartGame () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll.StartGame () [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll+<DownLoadAssets>d__11.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll.StartGame () [0x00000] in <00000000000000000000000000000000>:0 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll.StartGame () [0x00000] in <00000000000000000000000000000000>:0 
  at LoadDll+<DownLoadAssets>d__11.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 ```

from hybridclr.

pirunxi avatar pirunxi commented on July 17, 2024

We will test you codes. Don't worry.we will help you solve this problem.

from hybridclr.

pirunxi avatar pirunxi commented on July 17, 2024

we test a slightly modified version of you code in hybridclr_trial projects.

  • run HybridCLR/Generate/All
  • run HybridCLR/Build/Win64

It runs correctly, we don't find any error.

we have test the project many times. It should be ok. Could you try the latest hybridclr_trial project again?

public class HotUpdateMain : MonoBehaviour
{

    public string text;

    // Start is called before the first frame update
    void Start()
    {

    }

    public static async void Init()
    {
        await LoadGame();
    }

    static async Task LoadGame()
    {
        Debug.Log("Load Game Called");
        //Load the Scenes 
        var sceneAb = await LoadDll.GetStreamingAssetBundle("prefabs");
        string[] scenePaths = sceneAb.GetAllScenePaths();
        foreach (var s in scenePaths)
            Debug.Log($"Scene: {s}");

    }
}

public class LoadDll : MonoBehaviour
{
    // ...  ignore other codes

    public static async Task<AssetBundle> GetStreamingAssetBundle(string dllName)
    {
        return AssetBundle.LoadFromMemory(GetAssetData(dllName));
    }

    void StartGame()
    {
        LoadMetadataForAOTAssemblies();

#if !UNITY_EDITOR
        var gameAss = System.Reflection.Assembly.Load(GetAssetData("Assembly-CSharp.dll"));
#else
        var gameAss = AppDomain.CurrentDomain.GetAssemblies().First(assembly => assembly.GetName().Name == "Assembly-CSharp");
#endif

        Type type = gameAss.GetType("HotUpdateMain");
        MethodInfo method = type.GetMethod("Init");
        method.Invoke(null, null);
    }
}

from hybridclr.

Clancey avatar Clancey commented on July 17, 2024

Sorry, I didn't realize there was an update since I posted the issue. I started over, and I have it working! Thanks for your quick response!

from hybridclr.

Clancey avatar Clancey commented on July 17, 2024

I am able to reproduce the bug!
https://github.com/Clancey/hybridclr_trial/tree/async_bug

from hybridclr.

pirunxi avatar pirunxi commented on July 17, 2024

We test the project, but we can't reproduce the bug. please sure:

  • install latest HybridCLR cpp codes by HybridCLR/Installer.. .
  • run HybridCLR/Generate/All before build games. You can simply run HybridCLR/Build/Win64 which automately calls HybridCLR/Generate/All before building.

from hybridclr.

pirunxi avatar pirunxi commented on July 17, 2024

Our english document site will be coming soon.

from hybridclr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.