-1

I'm trying to use XDocument class inside a Unity3D project on Windows 7.

I did the following:

  • added the reference System.Xml.Linq to the Mono project.
  • included the namespace:

    using System.Xml.Linq;
    
  • set the target framework to: Mono/.NET 3.5
  • clean and rebuild the project

But still Unity3D complains about it. Here's the error output in the console:

Assets/Scripts/Editor/RoadManager/RoadManager.cs(3,18): error CS0234: The type or namespace name `Linq' does not exist in the namespace `System.Xml'. Are you missing an assembly reference?

Any idea?

svick
  • 236,525
  • 50
  • 385
  • 514
Heisenbug
  • 38,762
  • 28
  • 132
  • 190

2 Answers2

4

This has been discussed many times before, but few of these answers are complete.

As has been said before, Unity3d only supports up to .NET version 2.0, and it seems System.Xml.Linq was introduced in .NET 3.5, besides the fact that it is not listed on the Unity3d compatibility list anywhere.

The only things to try are to set the Mono API compatibility level to 2.0 (Menu: Edit > Project Settings > Player and look in the Other Settings panel), but it seems that that was a mistaken solution for Linq2SQL.

Another possible solution is to add the DLL yourself into the Unity Editor as shown:

Try dragging the C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\System.Xml.Linq.dll file into the unity project window like you would a texture or other game asset.

If none of these yield ANY luck for you, then I'm afraid you are out of luck.

Community
  • 1
  • 1
CC Inc
  • 5,842
  • 3
  • 33
  • 64
1

Unity3D supports .Net 2.0 only, so setting compatibility to .net 3.5 in MonoDevelop/Visual Studio will not work. You will have to make do without the class. This shows what library classes are available:

http://docs.unity3d.com/Documentation/ScriptReference/MonoCompatibility.html

See also this post in UnityAnswers: http://answers.unity3d.com/questions/46039/can-not-reference-systemxmllinq.html

Jan Thomä
  • 13,296
  • 6
  • 55
  • 83