I am trying to use System.Threading.Tasks.Task in Unity for controlling IEnumerator functions. My code has work for about a year now but suddenly has stopped compiling in Visual Studio 2022. The strangest part is, Unity still compiles my code and even successfully builds. I've reduced my code as much as possible with still getting the error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class taskTest : MonoBehaviour
{
void Start()
{
System.Threading.Tasks.Task<int> task;
}
}
It also seems the error message itself is bugged out in Visual Studio. According to Microsoft: The type TypeName1 exists in both TypeName2 and TypeName3. But my error does not include TypeName3. My error says, CS0433: The type 'Task' exists in both 'Unity.Tasks,
screenshot of CS0433 error message
I am using Unity version 2020.3.11f1 as its the version I've been using for several months. I've tried updating to Unity Version 2020.3.35f1 but made no difference. I am using Visual Studio 2022 Version 17.2.2. I made sure the Tools for Unity plugin was updated. I tried reverting to VS 2019 Version 16.11.15 as that version worked for me in the past. It made no difference.
I am also using Firebase 9.0.0. That is what I need to use Tasks for, but it seems I get the error even without using anything Firebase in that script.
Final note: I can still compile and Build my app in Unity. This issue doesn't technically stop my production, BUT it prevents me from using the Attach To Unity button since VS doesn't compile which makes debugging far more painful.
CodePudding user response:
The using
directive prevents the ambiguity:
using System.Threading.Tasks;
CodePudding user response:
I found the solution here https://github.com/googlesamples/google-signin-unity/issues/117
I had to delete two files that firebase added
"Remove the 2 files unity.compat and unity.tasks from the parse folder. Make sure you do not delete it from inside the dotNet45 folder."