- Home /
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
:0
at System.MonoCustomAttrs.GetCustomAttributes (ICustomAttributeProvider obj, System.Type attributeType, Boolean inherit) [0x00000] in
:0
at System.MonoType.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in
:0
at Mono.CSharp.AttributeTester.GetObsoleteAttribute (System.Type type) [0x00000] in
:0
at Mono.CSharp.Expression.ResolveAsTypeTerminal (IMemberContext ec, Boolean silent) [0x00000] in
:0
at Mono.CSharp.MemberBase.ResolveMemberType () [0x00000] in
:0
at Mono.CSharp.MemberBase.Define () [0x00000] in
:0
at Mono.CSharp.InterfaceMemberBase.Define () [0x00000] in
:0
at Mono.CSharp.Property.Define () [0x00000] in
:0
at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers () [0x00000] in
:0
--- End of inner exception stack trace ---
at Mono.CSharp.TypeContainer+MemberCoreArrayList.DefineContainerMembers () [0x00000] in
:0
at Mono.CSharp.TypeContainer.DefineContainerMembers (Mono.CSharp.MemberCoreArrayList mcal) [0x00000] in
:0
at Mono.CSharp.Class.DefineContainerMembers (Mono.CSharp.MemberCoreArrayList list) [0x00000] in
:0
at Mono.CSharp.TypeContainer.DoDefineMembers () [0x00000] in
:0
at Mono.CSharp.Class.DoDefineMembers () [0x00000] in
:0
at Mono.CSharp.TypeContainer.Define () [0x00000] in
:0
at Mono.CSharp.ClassOrStruct.Define () [0x00000] in
:0
at Mono.CSharp.Class.Define () [0x00000] in
:0
at Mono.CSharp.RootContext.PopulateTypes () [0x00000] in
:0
--- End of inner exception stack trace ---
at Mono.CSharp.RootContext.PopulateTypes () [0x00000] in
:0
at Mono.CSharp.Driver.Compile () [0x00000] in
:0
at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in
:0
Im not an expert at C Sharp, however it would help contributers a lot if you had some source code in your question
Answer by Woutor · May 26, 2011 at 08:20 AM
from: http://answers.unity3d.com/questions/12884/does-a-plugin-work-independent-of-mono-framework.html
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.
Answer by Jozua · Feb 09, 2011 at 05:17 PM
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.
Answer by caqde · Apr 07, 2011 at 08:15 PM
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.
No, var is implicitly typed by the compiler: http://msdn.microsoft.com/en-us/library/bb383973.aspx Also remarks like these should be added as a comment rather as an answer as it is off topic.
Your answer
Follow this Question
Related Questions
How can I find xmlconfiguration files that I import from Web? 0 Answers
xml : FormatException: Input string was not in the correct format 1 Answer
The requested feature is not implemented 0 Answers
LINQ, XML, putting XML nodes into an array 2 Answers
XmlWriter.Create exception, "Could not find the file..." on Android 0 Answers