-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading Xml inside Invoke Lamda Expression #18
Comments
Simple question, did you give access to the directory where the file is located? |
Yes , I did , |
Well the exception message says that your XML file is missing a root node. We would need to see your XML file and/or you code reading it to be able to troubleshoot. The exception message alone is not sufficient. |
using DotNetIsolator; internal class Program
} |
you can try with any sample xml you have |
I got the same error, but this worked for me. using DotNetIsolator;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Linq;
using Wasmtime;
var wasiConfig = new WasiConfiguration()
.WithPreopenedDirectory("PATH THAT CONTAIN XML FILE", "/")
.WithInheritedStandardOutput();
using var host = new IsolatedRuntimeHost()
.WithWasiConfiguration(wasiConfig)
.WithBinDirectoryAssemblyLoader();
using var runtime = new IsolatedRuntime(host);
runtime.Invoke(() =>{
var root = XElement.Parse(File.ReadAllText(@"/Sample.xml"));
Console.WriteLine($"Hello from {RuntimeInformation.OSArchitecture}");
Console.WriteLine($"{root.DescendantNodes().ToArray()[0].ToString()}");
}); This worked too: using DotNetIsolator;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Linq;
using Wasmtime;
var wasiConfig = new WasiConfiguration()
.WithPreopenedDirectory("PATH THAT CONTAIN XML FILE", "/")
.WithInheritedStandardOutput();
using var host = new IsolatedRuntimeHost()
.WithWasiConfiguration(wasiConfig)
.WithBinDirectoryAssemblyLoader();
using var runtime = new IsolatedRuntime(host);
runtime.Invoke(() =>{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(File.ReadAllText(@"/Sample.xml"));
XmlNodeList noteNodes = xmlDoc.SelectNodes("/notes/note");
foreach (XmlNode noteNode in noteNodes)
{
string to = noteNode.SelectSingleNode("to").InnerText;
string from = noteNode.SelectSingleNode("from").InnerText;
string subject = noteNode.SelectSingleNode("subject").InnerText;
string body = noteNode.SelectSingleNode("body").InnerText;
Console.WriteLine("To: " + to);
Console.WriteLine("From: " + from);
Console.WriteLine("Subject: " + subject);
Console.WriteLine("Body: " + body);
Console.WriteLine();
}
}); |
great thnx, it works when i tested on small files but when i tried with large file about (9 M) size, it gives another error |
her is the error |
Do not have a file that large, but maybe a stream can solve this? runtime.Invoke(() =>{
using StreamReader reader = new StreamReader(@"/Sample.xml");
var root = XElement.Load(reader);
Console.WriteLine($"Hello from {RuntimeInformation.OSArchitecture}");
Console.WriteLine($"{root.DescendantNodes().ToArray()[0].ToString()}");
}); and runtime.Invoke(() =>{
using StreamReader reader = new StreamReader(@"/Sample.xml");
var xmlDoc = new XmlDocument();
xmlDoc.Load(reader);
Console.WriteLine("To: " + xmlDoc.ChildNodes.Count);
XmlNodeList noteNodes = xmlDoc.DocumentElement.SelectNodes("/notes/note");
foreach (XmlNode noteNode in noteNodes)
{
string to = noteNode.SelectSingleNode("to").InnerText;
string from = noteNode.SelectSingleNode("from").InnerText;
string subject = noteNode.SelectSingleNode("subject").InnerText;
string body = noteNode.SelectSingleNode("body").InnerText;
Console.WriteLine("To: " + to);
Console.WriteLine("From: " + from);
Console.WriteLine("Subject: " + subject);
Console.WriteLine("Body: " + body);
Console.WriteLine();
}
}); Note: Using |
unfortunately it doesn't solve the issue |
I tried to read XML file inside the invoke Lamda Expression but it make exception as below
System.Xml.XmlException: Xml_MissingRoot
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
at System.Xml.Linq.XElement.Load(String uri)
while i tried to read the xml out side the invoke ,it can be read without any issue , are there any limitation for what i can do inside the invoke Expression?
The text was updated successfully, but these errors were encountered: