[英]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]'
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 根据他们的文档提供了自己的
Task
和Task<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.