x


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:

 

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

more ▼

asked Feb 03, 2011 at 04:42 PM

Woutor gravatar image

Woutor
118 10 10 16

Im not an expert at C Sharp, however it would help contributers a lot if you had some source code in your question

Feb 03, 2011 at 09:28 PM Vinpasso

good suggestion

Feb 04, 2011 at 08:44 AM Woutor
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered May 26, 2011 at 08:20 AM

Woutor gravatar image

Woutor
118 10 10 16

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Feb 09, 2011 at 05:17 PM

Jozua gravatar image

Jozua
11 1

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 07, 2011 at 08:15 PM

caqde gravatar image

caqde
1

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.

Apr 08, 2011 at 06:11 AM Woutor
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x379
x238
x180
x48
x1

asked: Feb 03, 2011 at 04:42 PM

Seen: 4511 times

Last Updated: May 26, 2011 at 08:24 AM