Type Task<> exists in both Unity.Tasks and mscorelib

Hello fellow coders. I have run across an infuriating issue. I am using System.Threading.Tasks in my project. I recently imported a new plugin (Google Firebase) which ships with it’s own dll (Unity.Tasks). Well, it seems like the geniuses at Google didn’t realize that Unity has full support of System.Threading.Tasks and decided to bundle that namespace with their dll. I cannot get rid of Unity.Tasks or it breaks Firebase. I cannot use an extern alias to reference mscorelib or I get errors stating that my code doesn’t return a Task<> (when it indeed did before I used the alias). I am at a loss of what I should do here. I would really like to use firebase as it is very easy to implement, but I also need to use Tasks in my project for asynchronous programming. Anybody have any bright ideas?

Note: I am using Unity 2020 beta 2 and .Net 4.0 with the IL2CPP backend. I have tried with .NET 2.0, mono backend, and Unity 2019.x. No success. Any and all help appreciated.

2 Likes

you can use namespace alias

edit:
In fact, I’m not sure which Task you want and which Task you had, and why you can’t specify it via namespace. I can’t understand the problem.

use Firebase tasks as Firebase.Task
use System tasks as System.Threading.Task
if you want to favor one task over the other, use i.e. using Task = System.Threading.Task;

or you can easily distinguish both if you just
using FBTask = Firebase.Task;
using SysTask = System.Threading.Task;

I hope I’m understanding you correctly.

2 Likes

So unfortunately I have tried using aliases already. The problem is that they both use the same namespace in different assemblies. so systask referencing System.Threading.Tasks wouldn’t work because System.Threading.Tasks exists in 2 different dll’s (mscorelib AND Unity.Tasks).

2 Likes

One workaround that almost worked was defining an alias in the reference tab in Visual Studio. I then called extern alias above my using statements. However for some reason that changed the type that my Task was so I couldn’t use my async method

Can you upload a minimal example that’s already set up to produce the error and ready to fiddle with?

I don’t know, maybe this can help you
https://stackoverflow.com/questions/56422962/unity3d-the-type-task-exist-in-both-unity-tasks-and-mscorelib

1 Like

I have tried that post, the fix does not work in my case

What about:

The fix that worked from me came from this GitHub issue

  • Remove the Unity.Compat and Unity.Tasks dlls from the Parse/ root folder
  • Enable the Unity.Compat and Unity.Tasks dlls in the Parse/dotnet45/ folder
46 Likes

I was able to fix it. Sorry I have not answered. I uninstalled Firebase from my project and re-installed it using the Package Manager (with .NET set to 4.x). I can now use System.Threading.Tasks just fine with Firebase working as well. One thing to note is (for now) Firebase does not work on Android builds in the Unity 2020 beta. Just food for thought.

1 Like

The @bellicapax solution worked! Thanks @ for share solution.

2 Likes

The @bellicapax solution worked for me too ! Thanks guys !

1 Like

Thanks @bellicapax works for me!

1 Like

Thanks @bellicapax ! It works for me too !

1 Like

Solved for me!
I deleted Assets/Parse/Plugin Unity.Compact and Tasks, but not the dotnet45 folder

10 Likes

This is still a working solution as of today.

1 Like

Excellent!
Thanks!

2 Likes

i did it and it is work for me c# - unity3d : The type "task" exist in both Unity.Tasks and mscorelib - Stack Overflow

It works still