puerts icon indicating copy to clipboard operation
puerts copied to clipboard

[Unity] 安卓真机TS调用c#报错 TypeError: task.GetAwaiter(...).OnCompleted is not a function

Open daodaozhangnianxi opened this issue 4 years ago • 3 comments

error log | 日志或报错信息

1 2

context | 编译/运行环境

Unity 2019.4.21f1c1 (64-bit) 谷歌 pixel3 安卓10 操作系统

how to reproduce | 复现步骤

  1. 在ts里去调用 c# 异步方法 2. 3.

more | 其他

    public static async Task LoadFairyGUIPackage(string address, string packageName)
    {
        var pkgAsset = await Addressables.LoadAssetAsync<TextAsset>(address).Task;

        UIPackage.AddPackage(
            pkgAsset.bytes,
            packageName,
            async (string name, string extension, Type type, PackageItem ite) =>
            {
                Log.Debug(LogGroups.Engine, $"{name}, {extension}, {type.ToString()}, {ite.ToString()}");

                if (type == typeof(Texture))
                {
                    Texture t = await Addressables.LoadAssetAsync<Texture>(name + extension).Task;
                    ite.owner.SetItemAsset(ite, t, DestroyMethod.Custom);

                }
            });
        Addressables.Release(pkgAsset);
    }

调用的Promise

function taskToPromise(task) {
    return new Promise((resolve, reject) => {
        task.GetAwaiter().OnCompleted(() => {
            let t = task;
            task = undefined;
            if (t.IsFaulted) {
                if (t.Exception) {
                    if (t.Exception.InnerException) {
                        reject(t.Exception.InnerException.Message);
                    } else {
                        reject(t.Exception.Message);
                    }
                } else {
                    reject("unknow exception!");
                }
            } else {
                resolve(t.Result);
            }
        });
    });
}

daodaozhangnianxi avatar Apr 21 '22 09:04 daodaozhangnianxi

有试过生成System.Runtime.CompilerServices.TaskAwaiter或者尝试其他防裁剪的手段吗

zombieyang avatar Apr 21 '22 11:04 zombieyang

生成过也没有用 还是报错

daodaozhangnianxi avatar Apr 22 '22 01:04 daodaozhangnianxi

#793 同样的问题

@daodaozhangnianxi 为什么把这个关掉了?

zombieyang avatar Apr 28 '22 04:04 zombieyang