Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a .NET 2 application to run on a Linux environment. So I write code for reading XML document

Something like this:

C#
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(SettingsName);
XmlNodeList xmlNodeList= xmldoc.SelectNodes("/settings/devicesettings/");


After that I foreach the XmlNodeList with

C#
foreach (XmlNode xn in xmlNodeList)

But when it reaches the
C#
foreach


Throws exception:

C#
An exception was thrown by the type initializer for System.Console


InnerException
C#
Exception: handle
   Parameter name: Invalid.
   StackTrace: System.ArgumentException: handle
   Parameter name: Invalid.
     at System.IO.FileStream..ctor (IntPtr handle, FileAccess access, Boolean ownsHandle, Int32 bufferSize, Boolean isAsync, Boolean isZeroSize) [0x00000] in <filename unknown>:0
     at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (intptr,System.IO.FileAccess,bool,int,bool,bool)
     at System.Console.Open (IntPtr handle, FileAccess access, Int32 bufferSize) [0x00000] in <filename unknown>:0
     at System.Console.OpenStandardError (Int32 bufferSize) [0x00000] in <filename unknown>:0
     at System.Console..cctor () [0x00000] in <filename unknown>:0

So please advice what and why is going on?
Posted
Comments
Sergey Alexandrovich Kryukov 29-Oct-15 3:31am    
Are you saying it works on Windows and not on Mono, or what? How about Mono for Windows? Same file, same everything?
—SA
Zhivko Kabaivanov 29-Oct-15 4:03am    
I am running Ubuntu and MonoDevelop.
Sergey Alexandrovich Kryukov 29-Oct-15 10:33am    
Did you check xmlModeList for null? Is the application target "console"? It should not make any difference, but...
—SA
Zhivko Kabaivanov 29-Oct-15 10:35am    
doc has loaded the xml file. But xmlnodelist is null

its a winforms app
Sergey Alexandrovich Kryukov 29-Oct-15 10:52am    
But then don't iterate through it. What's the problem?
You tend not to answer to most questions, you know...
—SA

1 solution

It's a mono bug. Try updating your mono version to the latest available. You can get the latest version directly from the Mono project. Don't rely on the distribution packed version, because usualy they are far behind the official latest version:
http://www.mono-project.com/docs/getting-started/install/linux/[^]
 
Share this answer
 
Comments
Zhivko Kabaivanov 29-Oct-15 4:04am    
Its strange because it runs in the MonoDevelope IDE but when I run it in File System it blows up. Also Can I ask you something else?
phil.o 29-Oct-15 4:24am    
If you have another question, you should open a new one.
And if this answer was useful to you, you should mark it as answered, and give the note you think webmaster442 deserves.
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900