简体   繁体   English

无法将 System.Threading.Tasks.Task... 转换为 System.Threading.Tasks.Task... 尽管看似相同的类型

[英]Cannot convert System.Threading.Tasks.Task… to System.Threading.Tasks.Task… despite seemingly being same type

I'm getting a strange error in Rider eluding to the fact that I am trying to convert to a Task in a way that's not allowed.我在 Rider 中遇到了一个奇怪的错误,因为我试图以一种不允许的方式转换为 Task。 The odd part is that the types seem to be an exact match.奇怪的是,这些类型似乎完全匹配。

Code throwing error代码抛出错误

        public IEnumerator GetCatalogItem_LevelDataId_PlayFabCatalogItemFound(string levelName,long levelDataId)
        {
            //Arrange
            const string getCatalogItemCloudFunctionName = "getCatalogItem";
            var data = new Dictionary<string, object>
            {
                {"itemId", levelDataId.ToString()}
            };
            //Act
            var result = FirebaseFunctions.DefaultInstance
                .GetHttpsCallable(getCatalogItemCloudFunctionName)
                .CallAsync(data);
            //BUG ERROR IS SHOWN ON result BELOW (SEE ATTACHED IMAGE)
            yield return result.AsIEnumerator<HttpsCallableResult>();
            var catalogItem = (IDictionary)result.Result.Data;
            //Assert
            Assert.AreEqual(levelName,catalogItem["DisplayName"].ToString());
        }

Task Extention Method Used使用的任务扩展方法

    public static class TaskExtensions
    {
        /// <summary>
        /// Converts a <see cref="System.Threading.Tasks.Task"/> to <see cref="IEnumerator"/> (helps with unity coroutines)
        /// </summary>
        /// <param name="task">The task to convert</param>
        /// <returns>An IEnumerator which waits till the task has been completed</returns>
        public static IEnumerator AsIEnumerator(this Task task)
        {
            while (!task.IsCompleted)
            {
                yield return null;
            }

            if (task.IsFaulted)
            {
                throw task.Exception;
            }
        }
        
        /// <inheritdoc cref="AsIEnumerator"/>
        public static IEnumerator AsIEnumerator<T>(this Task<T> task)
        {
            while (!task.IsCompleted)
            {
                yield return null;
            }

            if (task.IsFaulted)
            {
                throw task.Exception;
            }
        }
    }

Error Thrown抛出错误

Cannot convert instance argument type 'System.Threading.Tasks.Task<Firebase.Functions.HttpsCallableResult> [Firebase.Functions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]' to 'System.Threading.Tasks.Task<Firebase.Functions.HttpsCallableResult> [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]'无法将实例参数类型 'System.Threading.Tasks.Task<Firebase.Functions.HttpsCallableResult> [Firebase.Functions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]' 转换为 'System.Threading.Tasks.Task< Firebase.Functions.HttpsCallableResult> [mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]'

Task Error Image任务错误图像

Firebase comes with its own implementation of Task and Task<T> according to their documentation: https://firebase.google.com/docs/reference/unity/class/system/threading/tasks/task Firebase 根据他们的文档提供了自己的TaskTask<T>实现: https://firebase.google.com/docs/reference/unity/class/system/threading/tasks/task

Looks like you'll need to make which one is used more explicit in your code so the correct one is resolved as the reference you wish to use.看起来您需要在代码中更明确地使用哪一个,以便将正确的一个解析为您希望使用的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型&#39;void&#39;隐式转换为&#39;System.Threading.Tasks.Task&#39; - Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task' 无法隐式转换类型&#39;System.Threading.Tasks.Task - Cannot implicitly convert type 'System.Threading.Tasks.Task 无法将类型&#39;bool&#39;隐式转换为&#39;System.Threading.Tasks.Task&#39; - Cannot implicitly convert type 'bool' to 'System.Threading.Tasks.Task' “System.Func`1[System.Threading.Tasks.Task]”类型的表达式不能用于返回类型“System.Threading.Tasks.Task” - Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task' 类型&#39;System.Threading.Tasks.Task&#39;无法序列化 - Type 'System.Threading.Tasks.Task' cannot be serialized 找不到 System.Threading.Tasks.Task 方法 - System.Threading.Tasks.Task Method Not Found 找不到方法:'System.Threading.Tasks.Task`1<!--!0--> - Method not found: 'System.Threading.Tasks.Task`1<!!0> 无法将类型&#39;System.Collections.Generic.List &lt;&gt;&#39;隐式转换为&#39;System.Threading.Tasks.Task &lt;&gt;&gt; - Cannot implicitly convert type 'System.Collections.Generic.List<>' to 'System.Threading.Tasks.Task<>> System.Threading.Tasks.Task`1 [ <myType> ]被退回 - System.Threading.Tasks.Task`1[<myType>] being returned 无法将类型void隐式转换为System.Threading.Tasks.Task <bool> - Cannot implicity convert type void to System.Threading.Tasks.Task<bool>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM