- Home /
Impossible reference Issue
Assets/Scripts/Data.cs(3,18): error CS0234: The type or namespace name \`Script' does not exist in the namespace \`System.Web'. Are you missing an assembly reference?
My file is Data.cs -> using System.Web.Script.Serialization;
When I try to Edit References one of two things happens - 1. ) the build fails because of the above error and prevents me from being able to Edit References 2. ) i comment out the offending code and go to Edit Reference, checkmark the Web.Extensions option which is what I've learned is the correct one, uncomment the code and the error goes away, go to Unity which still complains with the above error, I go back to Monodevelop and suddenly have the same error again.
Answer by Bunny83 · Nov 22, 2017 at 04:48 AM
Once and for all you can't manually edit external references in your C# project for several reasons:
First of all Unity doesn't use the project it generates at all. It just generates the project so it can be opened in a scripting IDE like VisualStudio or MonoDevelop.
Second Unity will actually overwrite the project each time it syncs the project. That happens whenever a script gets added / removed or if you simply move a script around inside Unity (move it from one folder to another).
Finally Unity doesn't use any external references at all. Unity has it's framework and some core assemblies which it automatically references when it builds / compiles your scripts. Unity doesn't rely on an installed .NET or Mono framework on the endusers device. Unity includes the Mono framework in the build. If you want to use a non-core / non-automatically-included assembly you have to physically copy that assembly and all it's dependencies into your project's assets folder.
So you can't just link your project to externally located assemblies. When you actually copy an assembly into your project it will be automatically added to the references. Of course not every assembly can be included in a Unity project as it might has unsupported dependencies or rely on native code which might not be available for your target platform.
Note that for platforms which do not use an embedded scripting runtime (like Windows Phone afaik which uses the actual .NET the OS provides) the behaviour might be different. Also certain thing could change in the future. However since I work with Untiy (version 2.6 around 2010) nothing has changed so far.
thanks for the help, but i'm afraid i'm stuck - physically copy that assembly and all it's dependencies into your project's assets folder. I found System.Web.Extensions.dll and copied it over to Assets/Scripts/Assemblies, is that right? It's not having any effect on my issue. If this issue has existed for at least 7 years, shouldn't there be an easy solution? If i checkmark the reference and I also check 'local copy' one would think that an actual local physical copy is made if that's what unity needs...
I just copied the "System.Web.Extensions.dll" located at:
C:\Program Files\Unity\Editor\Data\$$anonymous$$ono\lib\mono\2.0\
Into my test project. I created this test class:
using UnityEngine;
using System.Web.Script.Serialization;
public class TestData
{
public string someText = "Hello world";
}
public class WebScriptSerializationTest : $$anonymous$$onoBehaviour
{
void Start ()
{
var serializer = new JavaScriptSerializer();
Debug.Log("Data: " + serializer.Serialize(new TestData()));
}
}
attached it to a gameobject and run the game. I get a Log in the console that reads:
Data: {"someText":"Hello world"}
What's your exact problem? Some assemblies requires .NET 2.0 compatibility however my test project is set to ".NET 2.0 Subset" (the default).
ps: I copied the assembly into `Assets\UATests\WebScriptSerialization` however the path shouldn't really matter.
awesome thank you so much! $$anonymous$$y problem seems to have been that I copied the .dll from \lib\mono\gac\ ins$$anonymous$$d of \lib\mono\2.0\ . but now I'm getting a new error TypeLoadException: Could not load type 'System.Web.UI.Script$$anonymous$$anager' from assembly 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, Public$$anonymous$$eyToken=31bf3856ad364e35'
I copied over all System.Web.X.dll's but no luck. Going to search now.
BTW, I'm on $$anonymous$$ac, maybe that is my problem.
Answer by ZeN12 · Nov 21, 2017 at 09:27 AM
Check API compatibility level. Try to set it to .NET 2.0. File -> Build Settings -> Player Settings -> Other Settings.
Answer by pako · Nov 21, 2017 at 01:04 PM
As far as I can tell System.Web.Script.Serialization is not included in the Mono version that Unity uses. The last Mono Compatibility List that I could find is this:
https://docs.unity3d.com/401/Documentation/ScriptReference/MonoCompatibility.html
...which is outdated.
With Unity 2017.1 an experimental version of the core scripting runtime upgraded to Mono/.NET 4,6 runtime was introduced: https://blogs.unity3d.com/2017/07/11/introducing-unity-2017/
However, in VS2017 System.Web.Script.Serialization is not available in IntelliSense, which leads me to believe that this namespace is still not available in the Mono version that Unity uses.
any idea how i can get JavascriptSerializer or if its a thing in the newer verison?
@$$anonymous$$ I believe that @Bunny83 has already answered this question. $$anonymous$$aybe you should consider different ways to achieve what you want.
thanks they posted that answer an hour after i checked back and commented to you so i missed it, unfortunately what they say about physically copying over the assembly doesn't help me or i'm not doing everything correctly as the advice is vague, I believe I can solve my issue though by using the guide here https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
Your answer
Follow this Question
Related Questions
Command line build fails after updating to Unity 2019.4 1 Answer
How to add Unity API reference to Visual Studio's keyboard shortcuts? 1 Answer
.NET dll seen as native in Unity3D 1 Answer
accessing a class by interface requries reference to other unrelated interface's assembly 0 Answers
How to properly use class from custom DLL project in 'Assembly-CSharp-Editor' 1 Answer