+3
Fixed

System.Threading does not work with .NET 4.6

tiZyJoshi 3 years ago updated by jam joel 3 weeks ago 32 2 duplicates

Hi,

So I just played around with Bolt and set up a project with all my standard assets and I noticed that I have issues with Bolt and UniRx (and basically all other  scripts that use System.Threading). It says that all the System.Threading types are both defined multiple times. In System.Threading and mscorlib. I noticed you import a System.Threading.dll. I deleted it but - as expected - got even more issues (most of the errors are blanks though :/). Any ideas?

BR

Joshi

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Answer

Answer

Here is a workaround discovered by Discord user @syynth. I haven't had time to test it myself, but apparently it works in the mean time!

1. Create an empty file named mcs.rsp right under the Assets folder

2. Add this line to the mcs.rsp file:

-reference:mscorlib="C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.6-api\mscorlib.dll"

3. Add these in your usings for scripts using System.Threading:

extern alias mscorlib;
using mscorlib::System.Threading.Tasks;

4. Add your alias in the Visual Studio solution explorer reference list if you want to build from VS:


Note: Documentation generation will still fail, but this doesn't prevent Bolt from working

Duplicates 2

Pending Review

What do you mean "blank errors"? That's a bit hard for me to debug ;) Any screenshot would help.

What if you delete the System.Threading.dll from UniRx rather than from Bolt? Does it help?

Hey!

Thank you for your fast response, Im sorry for the bad description of the problem... Here is a screenshot of the problems causes by deleting System.Threading.dll from the Plugins/Assemblies Folder.

UniRx doesnt come with a System.Threading.dll

the typeloadexception has some more info...

Thanks for the screenshots. This is the first time I see a blank error!

1) Did you try restarting the editor after deleting the DLL? It might force reload the assemblies.

2) If that doesn't help, can you restore the System.Threading.dll from Bolt and copy/paste the exact stack trace of the error here?

+1

"Have you tried turning it off and on again?"

I can't believe this actually worked, lol. I didnt even have to delete your System.Threading.dll. But I got no remaining errors and my testscenes all work.

Sorry to bother you! And thanks for the help!

BR

Fixed

Hahaha, no problem, glad you got it working. Restarting is the oldest trick in the book for a reason! ;)

I'm so sorry, I was celebrating too early. My issue is still present, but it's easily recreateable:

  • create new project
  • in "Player Settings" set "Scripting Runtime Version" to 4.6
  • import Bolt
  • create a script, import "System.Threading.Tasks" and declare a "Task" variable. 

I'll have a look into it then. I'm worried that this means .NET 4.6 includes threading, whereas .NET 3.5 did not. If so I'll either have to provide two sets of DLL's, or support only .NET 4.6. I know Unity is making 4.6 default and ending the experimental tag in Unity 2017.2, so I might make the switch then.

In the mean time, if you don't use .NET 4.6, does it work?

+1

it's working for 3.5, yes


/e when i restarted my project for some reason unity reset to .net 3.5. thats why my errors were all gone :/

+1
Confirmed

I was able to reproduce the issue and it's what I dreaded, unfortunately.

System.Threading is now included as part of mscorlib (the core of .NET) when you target 4.6 instead of 3.5.

Bolt imports another System.Threading DLL manually from the TaskParallelLibrary because it didn't exist back in .NET 3.5, and it is required for some editor features.

Unless I start providing two entire different sets of DLL's, one for 3.5 and one for 4.6, there is no way to go around this issue I'm afraid.

Here's what I'll do:

  • Try to remove any use of System.Threading in Bolt (might not be possible)
  • Maybe require .NET 4.6 and Unity 2017.2 when it is released

In the long term, supporting two major .NET framework versions will not be viable. I might take the opportunity while the plugin is still young to force the switch to 2017.2 / .NET 4.6 as a requirement.

In the mean time, you can stick to .NET 3.5 to avoid the issue.

Hi,

I'm working on a project in Unity that requires .NET 4.6 (Unity 2017.3). I was trying to import bolt (version 1.2.2), but unfortunately I've hit a System.Threading defined multiple times issue. Last comment here is 5 months old, how's the situation now? Is there set of dlls for 4.6 available somewhere maybe?

I'm now facing this issue, also. Any progress?

I bought your plugin just today, and it's totally broken on Unity 2017.3.0 with .NET 4.6.

+3

It's not easy, but it's coming! :D

Unfortunately, there seems to be a Unity issue with .NET 4.6 that prevents importing the Bolt DLL's. I'm in contact with the developers here and they'll have a look at the bug report:

https://forum.unity.com/threads/monobehaviours-and-scriptableobjects-are-not-recognized-in-4-6-dll.521487/

This is delayed until then.

Answer

Here is a workaround discovered by Discord user @syynth. I haven't had time to test it myself, but apparently it works in the mean time!

1. Create an empty file named mcs.rsp right under the Assets folder

2. Add this line to the mcs.rsp file:

-reference:mscorlib="C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.6-api\mscorlib.dll"

3. Add these in your usings for scripts using System.Threading:

extern alias mscorlib;
using mscorlib::System.Threading.Tasks;

4. Add your alias in the Visual Studio solution explorer reference list if you want to build from VS:


Note: Documentation generation will still fail, but this doesn't prevent Bolt from working

+2
Unity Bug

Hi Aaron,

Unfortunately, I'm stuck waiting for a Unity fix here. The .NET 4.6 DLLs without System.Threading duplicates are ready, but they don't get imported properly by Unity. This is all described in this thread: https://support.ludiq.io/communities/5/topics/233-systemthreading-does-not-work-with-net-46

You can add your vote to the issue here: https://issuetracker.unity3d.com/issues/monobehaviours-and-scriptable-objects-are-not-recognized-in-4-dot-6-dll

I'll try to see if I have a contact at Unity that could get this escalated faster...

+5

Just a heads up: I pinged one of my contacts at Unity to get this issue bumped in the queue and I'm hoping to hear back soon!

+3

Is there any update on this?

+1
Fixed in Alpha

Good news!

While working on v.1.4 Alpha, I realized that the DLLs now imported properly in Unity 4.6. I suspect this is because I started using the type-forwarded assemblies that were modularized in 2017.2 as references, instead of the non-modular references of 2017.1. 

Regardless, Bolt 1.4 now seems to be perfectly working with .NET 4.6 and Unity 2018.

Of course, 1.4 is still in Alpha & I would love your feedback on this when it lands in Beta.

Thank you all for your patience in this matter!

Hi. The problem still exists. Mentioned workaround not working.

Need help.

Hi,

The workaround is no longer needed since 1.4. All you have to do is download the .NET 4.x version off the downloads page: https://ludiq.io/bolt/download/1.4.0f11


Because .NET 4.x is not default yet on LTS versions of Unity, the Asset Store version ships with the .NET 3.x Bolt version. This might explain the issue you're seeing.

i'm in need of the 4.x version but there was no invoice generated for my purchase. advice?


cheers!

Tim, if you purchased Bolt from the asset store Unity would have send you and email that will have a PDF with the invoice. Otherwise you will need to reach out to Lazlo or Hassan using the link under the search bar on the forum. 

+1

seems they were simply a bit slow this morning, just received, cheers!

the link for .NET 4.x is gone :(