(VS2008 - VB.Net - Compact Framework) DataSet.ReadXml metod fails
-
Hello, in my application taht runs in Windows Embedded Compact 7 OS (with Compact Framework 3.5) I have a problem reading a xml file with DataSet.ReadXml. I have made a little test to reproduce the problem:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dati As DataSet = New DataSet("Programmazione")
Dim fname As String
Dim j As Int32Try fname = "\\Program Files\\SmartDeviceProject1\\default\_19.prg" 'this works 'fname = "\\Program Files\\SmartDeviceProject1\\default\_20.prg" 'this doesn't work Dim fs As New FileStream(fname, FileMode.Open, FileAccess.Read) Dim xr As XmlReader = System.Xml.XmlReader.Create(fs) dati.Clear() j = dati.ReadXml(xr) 'j = 3 = XmlReadMode.InferSchema xr.Close() fs.Close() Catch ex As Exception MessageBox.Show(ex.ToString) End Try
End Sub
I have two test file: default_19.prg and default_20.prg. The first is a little shorter than the second and it is read without problem, the second fails without raising an exception (at least an exception that I can catch). I don't know if it is a file dimension problem or something else. The two files are quite long and I apologize for this but I post them here otherwise who could help me? default_19.prg
False 4:00:00 PM 2 1
1
zona 1
1
2
0
10
12:00:00 PM6:00:00 AM
6:15:00 AM
12:15:00 AM
0
50
1
16:15:00 AM
5:45:00 PM
11:30:00 AM
50
50
2
05:45:00 PM
6:00:00 PM
12:15:00 AM
50
5
3
2 -
Hello, in my application taht runs in Windows Embedded Compact 7 OS (with Compact Framework 3.5) I have a problem reading a xml file with DataSet.ReadXml. I have made a little test to reproduce the problem:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dati As DataSet = New DataSet("Programmazione")
Dim fname As String
Dim j As Int32Try fname = "\\Program Files\\SmartDeviceProject1\\default\_19.prg" 'this works 'fname = "\\Program Files\\SmartDeviceProject1\\default\_20.prg" 'this doesn't work Dim fs As New FileStream(fname, FileMode.Open, FileAccess.Read) Dim xr As XmlReader = System.Xml.XmlReader.Create(fs) dati.Clear() j = dati.ReadXml(xr) 'j = 3 = XmlReadMode.InferSchema xr.Close() fs.Close() Catch ex As Exception MessageBox.Show(ex.ToString) End Try
End Sub
I have two test file: default_19.prg and default_20.prg. The first is a little shorter than the second and it is read without problem, the second fails without raising an exception (at least an exception that I can catch). I don't know if it is a file dimension problem or something else. The two files are quite long and I apologize for this but I post them here otherwise who could help me? default_19.prg
False 4:00:00 PM 2 1
1
zona 1
1
2
0
10
12:00:00 PM6:00:00 AM
6:15:00 AM
12:15:00 AM
0
50
1
16:15:00 AM
5:45:00 PM
11:30:00 AM
50
50
2
05:45:00 PM
6:00:00 PM
12:15:00 AM
50
5
3
2steve_9496613 wrote:
in my application taht runs in Windows Embedded Compact 7 OS
Works as expected when I run it on the desktop. Step through it with the debugger, and verify the path to the XML.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
steve_9496613 wrote:
in my application taht runs in Windows Embedded Compact 7 OS
Works as expected when I run it on the desktop. Step through it with the debugger, and verify the path to the XML.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Thanks Eddy. The path is right. When I go step by step with the debugger everything just stop at the line that read the XML. Today I finnaly get an error message in the device:
System.StackOverflowException: StackOverflowException
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
...Now I know the reason (I think...) but not the solution... Any idea? Thanks
-
Thanks Eddy. The path is right. When I go step by step with the debugger everything just stop at the line that read the XML. Today I finnaly get an error message in the device:
System.StackOverflowException: StackOverflowException
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
...Now I know the reason (I think...) but not the solution... Any idea? Thanks
-
Thanks Eddy. The path is right. When I go step by step with the debugger everything just stop at the line that read the XML. Today I finnaly get an error message in the device:
System.StackOverflowException: StackOverflowException
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
at System.Xml.Schema.SequenceNode.ConstructPos(BitSet firstpos, BitSet lastpos, Bitset[] followpos)
...Now I know the reason (I think...) but not the solution... Any idea? Thanks
To build on Richards' answer, might help to make the files smaller; cut them in chuncks before reading them. I assume you'll be importing them into a database?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
A
StackOverflowException
means that your process has run out of local memory. You can try increasing the stack size or request heap space to hold whatever data is causing the overflow.Thanks Richard. How can I increase the stack size? I use Visual Studio 2008 and this is a smart device VB.net project. I don't find any specific setting in the project properties
-
Thanks Richard. How can I increase the stack size? I use Visual Studio 2008 and this is a smart device VB.net project. I don't find any specific setting in the project properties
-
To build on Richards' answer, might help to make the files smaller; cut them in chuncks before reading them. I assume you'll be importing them into a database?
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Hi Eddy. These files are created by the application and contain user programming. They can be larger or smaller depending on what the user does. When the user changes something, the file is updated. While the application is running, there is no problem. When the application is closed and restarted, settings are loaded from the file and here is the crash. I load the XML file in a DataSet because I can read all with a line of code with ReadXml and then I copy the DataSet content in the different internal variables and structures; I don't use a real database. To limit the file size and use more than one if one file is not enough could be a solution. If ReadXml works fine in a desktop environment with full .NET, perhaps there is a bug in the .NET Compact Framework version of this function?
-
Hi Eddy. These files are created by the application and contain user programming. They can be larger or smaller depending on what the user does. When the user changes something, the file is updated. While the application is running, there is no problem. When the application is closed and restarted, settings are loaded from the file and here is the crash. I load the XML file in a DataSet because I can read all with a line of code with ReadXml and then I copy the DataSet content in the different internal variables and structures; I don't use a real database. To limit the file size and use more than one if one file is not enough could be a solution. If ReadXml works fine in a desktop environment with full .NET, perhaps there is a bug in the .NET Compact Framework version of this function?
steve_9496613 wrote:
I load the XML file in a DataSet because I can read all with a line of code with ReadXml and then I copy the DataSet content in the different internal variables and structures; I don't use a real database.
You are using an export-format as a datastore; use a real database and the problem is gone.
steve_9496613 wrote:
If ReadXml works fine in a desktop environment with full .NET, perhaps there is a bug in the .NET Compact Framework version of this function?
Sure, maybe. Maybe there's some difference between the frameworks, simply because a device isn't as powerfull as a real desktop, with more limitations.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
steve_9496613 wrote:
I load the XML file in a DataSet because I can read all with a line of code with ReadXml and then I copy the DataSet content in the different internal variables and structures; I don't use a real database.
You are using an export-format as a datastore; use a real database and the problem is gone.
steve_9496613 wrote:
If ReadXml works fine in a desktop environment with full .NET, perhaps there is a bug in the .NET Compact Framework version of this function?
Sure, maybe. Maybe there's some difference between the frameworks, simply because a device isn't as powerfull as a real desktop, with more limitations.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Eddy Vluggen wrote:
You are using an export-format as a datastore; use a real database and the problem is gone.
You're right, I didn't use a real database because of my lack of knowledge about databases.
-
I am not a VB expert so not sure what you would need to do. I guess Google is the place to look. But in reality, this exception is a warning that your application needs reworking in some way.
Hi Richard, surely a StackOverflowException means something bad, for this reason I tried to reproduce the problem with few clean lines of code. I managed to replicate the problem just with a Form, a Button and the code I posted. This does not mean that the complete application would not benefit from a reworking (...) but it seems to me that in this situation the problem is in a single line of code. Probably, as Eddy suggests, I should use another way to store and read the application settings.
-
Hi Richard, surely a StackOverflowException means something bad, for this reason I tried to reproduce the problem with few clean lines of code. I managed to replicate the problem just with a Form, a Button and the code I posted. This does not mean that the complete application would not benefit from a reworking (...) but it seems to me that in this situation the problem is in a single line of code. Probably, as Eddy suggests, I should use another way to store and read the application settings.
steve_9496613 wrote:
surely a StackOverflowException means something bad
Yes, as I already explained it means you have used up all your local memory (stack space). If that is because you are reading huge amounts of data then that is the area that needs investigation. If that is not the reason (which is also possible) then more debugging may be required. In either case the only way to be sure is to use the debugger to see what is happening inside the application under real load.
-
Eddy Vluggen wrote:
You are using an export-format as a datastore; use a real database and the problem is gone.
You're right, I didn't use a real database because of my lack of knowledge about databases.
steve_9496613 wrote:
You're right, I didn't use a real database because of my lack of knowledge about databases.
Take your time and give it a try; it will not only benefit you in this project, but all the projects to come. If stuck, simply post the code here :) I'd recommend SQLite, since you don't require a dedicated server or multi-user access. It's free, small and there's the benefit that you can copy the db to your desktop and edit its contents there.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
steve_9496613 wrote:
You're right, I didn't use a real database because of my lack of knowledge about databases.
Take your time and give it a try; it will not only benefit you in this project, but all the projects to come. If stuck, simply post the code here :) I'd recommend SQLite, since you don't require a dedicated server or multi-user access. It's free, small and there's the benefit that you can copy the db to your desktop and edit its contents there.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Thanks for your advice Eddy, I'll give it a try. I have already tried SQLite in C++ (Embarcadero C++Builder) but I was not really satisfied from what I managed to do... I see that here there are some articles as "Using SQLite in C#/VB.Net" that seems to be a good point to start.
-
Thanks for your advice Eddy, I'll give it a try. I have already tried SQLite in C++ (Embarcadero C++Builder) but I was not really satisfied from what I managed to do... I see that here there are some articles as "Using SQLite in C#/VB.Net" that seems to be a good point to start.
-
steve_9496613 wrote:
surely a StackOverflowException means something bad
Yes, as I already explained it means you have used up all your local memory (stack space). If that is because you are reading huge amounts of data then that is the area that needs investigation. If that is not the reason (which is also possible) then more debugging may be required. In either case the only way to be sure is to use the debugger to see what is happening inside the application under real load.
Thank you Richard. I'll try to dig deeper to find the reason because this is a loose cannon in my code.
-
Thank you Richard. I'll try to dig deeper to find the reason because this is a loose cannon in my code.
-
Hello, in my application taht runs in Windows Embedded Compact 7 OS (with Compact Framework 3.5) I have a problem reading a xml file with DataSet.ReadXml. I have made a little test to reproduce the problem:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dati As DataSet = New DataSet("Programmazione")
Dim fname As String
Dim j As Int32Try fname = "\\Program Files\\SmartDeviceProject1\\default\_19.prg" 'this works 'fname = "\\Program Files\\SmartDeviceProject1\\default\_20.prg" 'this doesn't work Dim fs As New FileStream(fname, FileMode.Open, FileAccess.Read) Dim xr As XmlReader = System.Xml.XmlReader.Create(fs) dati.Clear() j = dati.ReadXml(xr) 'j = 3 = XmlReadMode.InferSchema xr.Close() fs.Close() Catch ex As Exception MessageBox.Show(ex.ToString) End Try
End Sub
I have two test file: default_19.prg and default_20.prg. The first is a little shorter than the second and it is read without problem, the second fails without raising an exception (at least an exception that I can catch). I don't know if it is a file dimension problem or something else. The two files are quite long and I apologize for this but I post them here otherwise who could help me? default_19.prg
False 4:00:00 PM 2 1
1
zona 1
1
2
0
10
12:00:00 PM6:00:00 AM
6:15:00 AM
12:15:00 AM
0
50
1
16:15:00 AM
5:45:00 PM
11:30:00 AM
50
50
2
05:45:00 PM
6:00:00 PM
12:15:00 AM
50
5
3
2For online Course on .net Framework 4.5 using C# , Please Click here.