Can not reference System.Xml.Linq

Hi, I'm trying to use the System.Xml.Linq namespace to do some xml generation/parsing. Is there any way to get this to work?

I get these weird messages in Unity when I try to use XElement. The following code gives error messages:

var doc = new XDocument(new XElement("root"));

This code works:

var doc = new XDocument();

The error message I get is:

Internal compiler error. See the console log for more information. output was:
Unhandled Exception: Mono.CSharp.InternalErrorException: Assets/Scripts/Others/StartXmlSerializer.cs(12,14): StartXmlSerializer ---> Mono.CSharp.InternalErrorException: Assets/Scripts/Others/StartXmlSerializer.cs(32,21): StartXmlSerializer.Root ---> System.TypeLoadException: Could not load type 'System.ComponentModel.TypeDescriptionProviderAttribute' from assembly 'System.Xml.Linq'.
  at (wrapper managed-to-native) System.MonoCustomAttrs:GetCustomAttributesInternal (System.Reflection.ICustomAttributeProvider,System.Type,bool)
  at System.MonoCustomAttrs.GetCustomAttributesBase (ICustomAttributeProvider obj, System.Type attributeType) [0x00000] in <filename unknown>:0 
  at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at System.MonoType.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.AttributeTester.GetObsoleteAttribute (System.Type type) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Expression.ResolveAsTypeTerminal (IMemberContext ec, Boolean silent) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MemberBase.ResolveMemberType () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.MemberBase.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.InterfaceMemberBase.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Property.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.DefineContainerMembers (Mono.CSharp.MemberCoreArrayList mcal) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.DefineContainerMembers (Mono.CSharp.MemberCoreArrayList list) [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.DoDefineMembers () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.DoDefineMembers () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.TypeContainer.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.ClassOrStruct.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Class.Define () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.RootContext.PopulateTypes () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Mono.CSharp.RootContext.PopulateTypes () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0 
  at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0 

I had to work around this error by removing all use of XElement. Basicly I stopped using System.Xml.Linq and recoded my serializer to make use of System.Xml exclusively. Unfortunately this is just a poor work around rather than a proper fix.

Based on the code snippets I see either you are using C# and using its var command (which would work for certain things, but it shouldn't be used here) or you are using another language all together.

Anyways if this is indeed C# change your var to XDocument. var should only be used when you don't know for sure what type of variable is going to be sent to a function or class. If you are using var throughout your code you are slowing down your code and increasing the time it takes to compile your code along with bringing possible unnecessary bugs to your game.

If what I said is indeed what you are doing I would recommend reading up on C# and learning proper syntax for C#. All of your variables should either use int, float, double, bool, char, string, enum, or the name of a class. var should only be used when absolutely necessary.

I hope this helps with your problem.

from: Does a plugin work independent of MONO framework? - Questions & Answers - Unity Discussions

A .Net DLL isn’t the same as a normal
native code library. Your .Net DLL is
a big pile of .Net opcodes and is
expecting certain libraries to be
available in your GAC (Global Assembly
Cache).

Long answer long… no, the DLL will
not work if it requires things that
are available in .Net but not in
Unity’s version of Mono. If you really
wanna try your hacking hand at things,
you can copy your referenced .Net
assemblies into the Mono.framework
that’s in your Unity install.

I guess it’s not implemented in the version of Mono used by Unity and thus not available. A suggestion I read elsewhere was to use a C++ plugin that calls into a .Net assembly. This will allow the .Net assembly to use the Microsoft GAC instead of the Mono GAC.