Problem with .net 4.6 - The type `System.Object' is defined in an assembly that is not referenced.

Hello, Hopefully someone can help. I’m trying to use the following Imgur API:

I’m trying version 4.0.1 (The latest non-beta release). In my Solution, I set up a test project that successfully uses this API. The project is targeted to .Net4.5 and the Build/Advanced/Language version is set to “default”. The sample code uses “async” and “await” so I know C# 5 is needed, and apparently getting used in the sample project.

My project is called “2017”, and I’ve targeted all 3 of the following projects in VSS to target .net 4.6:
2017
2017.Eduitor
2017.Editor.Plugins

I’ve changed the language of my project to C#5.0 (which is needed by the async), and I’ve dropped ImgurApi.dll into my Assets folder.

The project is building in Visual Studio, but when I try to run my project in Unity, I get this error:

LogsUtil.cs(112,30): error CS0012: The type `System.Object' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

The line of code in question is this: (instantiating the ImgurClient):

3212732--245974--upload_2017-9-7_17-35-30.png

I’ve tried messing around with the references, but haven’t been able to resolve this. Does anyone have any idea for how to resolve this? I’ve spent a few hours working on this, so hopefully someone can help me proceed. I’d really love to get Imgur searches working in my game. Thanks a lot

It looks like a library is targeting .NET standard where System.Object lives in the System.Runtime assembly.

We are working on delivering .NET standard supporting soon (likely in 2017.2 or 2017.3). For now, it’s best to use libraries only target .NET Framework.

Additionally, unsupported but fun to try, you could try copying the System.Runtime assembly from your Editor install under the MonoBleedingEdge/lib/mono/4.5/Facades/ directory into your project.

1 Like

ok. I don’t really know what “.NET standard” is (compared to whatever Unity does currently support), but I guess you’re suggesting the 2017.1 may not support what I’m doing, and an upcoming version might? I’ll try your suggestion about copying the System.Runtime into my project and see what happens. If it still doesn’t work, then I suppose I’ll need to put this on the back-burner until the “standard” support you mentioned arrives.

Also another weird thing I noticed: When I’m using Visual Studio, occasionally I see the messages about how the projects have been changed by an external source (which of course is Unity), and it asks if I want to reload. When I do this, I noticed that the .net target version is being changed back to .NET 3.5 even though I have it set to 4.6 in Unity player settings. Have any idea why this would be happening? Thanks for your quick response. I was thinking that most likely no one would. Progress on the .NET stuff would be great in that it would allow a large number of new APIs to become available.

.NET Standard is a bit too involved to explain here: .NET Standard - .NET | Microsoft Learn

As for the project reloads. Do you have VSTU installed in your Visual Studio? The latest version?

Hi, I actually was able to get the new Imgur thing working after moving System.Runtime to my Assets folder. But then I had a similar issue with the System.Threading.Tasks.dll that was needed by another line. I tried finding that .dll and moving it to the Assets folder, and didn’t have any luck (not yet anyway). At one point I moved a version of System.Threading.Tasks.dll in, but then Unity reported some kid of error related to this. Now it seems that I’ve lose all my script references for the objects in my scene, so they now look like this:

3212776--245975--upload_2017-9-7_18-57-37.png

Do you know if there is a way to recover from this? Or do I need to revert to a backup? Thanks,

Regarding VSTU, I’m not sure. I’ll need to look into what this is, and if I have it installed.

For the scripts problem above, I was able to fix by deleting the metadata for my C# files and then closed and re-opened the project, and it recompiled and re-imported everything and now the scripts assignments seem to be back in place. whew!

For the System.Threading.Tasks issue I’m having, it’s showing this error in the console:

Assets/BuildAndDestroyCode/LogsUtil.cs(116,37): error CS0012: The type System.Threading.Tasks.Task1<Imgur.API.Models.IImage>’ is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

It seems to want version 4.0.0.0 of this, so I used the NuGet Package manager to install this. But still the code wouldn’t compile. I tried adding this .dll to the assets folder, but Unity doesn’t like the .dll and I get this error:

And here is the error I get for adding System.Threading.Tasks.dll

3212802--245976--upload_2017-9-7_19-22-0.png

Let me know if you have any more thoughts. It seems reasonably close to working, but perhaps it’s just not going to work. ?? thanks.

Regarding VSTU, I didn’t have time to check last night, but now see that this is Visual Studio Tools for Unity. Yes, I should have this, as I’ve been using Visual Studio integrated with Unity for over a year. My current status is:

  1. The project compiles with 0 errors in Visual Studio, and I have the single “System.Threading.Tasks” error shown above.
  2. Unity is continually trying to switch the V.S. project back to .Net 3.5 and C# 4 (I’ve switched it back probably 50 times now while troubleshooting this issue!).

If you have any thoughts on these 2 issues, please let me know. This seems tantalizingly close to working!

For #2, do you have an updated version of VSTU?

I haven’t, but will update now. I just ran across this other thread where someone was having the same issue, and updating VSTU was also the advice given. Thanks. Still hope to find a solution for #1!

Hi, so updating VSTU did fix Issue #2.

Regarding Issue #1,
I was able to get both VisualStudio and Unity to compile the code after dropping all the System.Threading* .dlls (there are 10 of them) from the MonoBleedingEdge/lib/mono/4.5/Facades/ folder to my Assets folder. Progress!

But when I execute my method, Unity freezes. The method in question is:

3213885--246056--upload_2017-9-8_12-13-56.png

The endpoint gets printed, but the method seems to freeze Unity when the GetImageAsync method is called.
The same method works fine when called from a ConsoleApplication project that I have in my Visuals studio solution.

You’ve helped a lot already, and thanks for that, but do you have any thoughts about what might cause this kind of thing or how to troubleshoot?

10 hours later and I finally have this working. Some how the freezing stopped, but the method wasn’t returning, and the method was exiting without printing any of the “image=” debug statements. I couldn’t debug the .dll I was using so I eventually installed the source. Eventually I figured out that the problem was a System.Net.WebException “Trust Failure”.

This was caused because the imgur service required https. Evidently the browsers trust the type of certificate used by default, but this was’t happening in Unity. At long last I found the following which provides some code for getting Unity to trust the cert.

This is one of those cases where I made just enough progress along the way to prevent me from giving up entirely. Sometimes you just need to use brute force trial and error, and a million Google searches, to get things working.
Thanks!

I migrated project from VS 2015 to VS 2018 and while building i am getting this error
AlertMgmt\AlertReportsAsCSV.cs(35):The type ‘System.Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.