|
Hy guys I want to serialize to xml a matrix od double bet when I try to do this:
XmlSerializer(typeof(double[,]));
I get a runtime error.
What is the correct way. p.s code snippet will be apprecited
Thank. Mirko
|
|
|
|
|
Convert the double[,] to double[][]
|
|
|
|
|
Thankyou a lot for the answer but for the following code
System.Xml.Serialization.XmlSerializer xmlSer =
new System.Xml.Serialization.XmlSerializer(typeof(double[][]));
when executed the compiler get the following message:
"The assembly with display name 'mscorlib.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=....' or one of its dependencies. Impossibile trovare il file specificato.
File name: 'mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=....'
=== Pre-bind state information ===
LOG: User = ....
LOG: DisplayName = mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=...., processorArchitecture=x86
(Fully-specified)
LOG: Appbase = ....
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=....
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=...., processorArchitecture=x86
LOG: Attempting download of new URL file:///.../bin/Debug/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///.../bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///.../bin/Debug/mscorlib.XmlSerializers.EXE.
LOG: Attempting download of new URL file://.../bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.EXE."
|
|
|
|
|
P.S
when I simply write
System.Xml.Serialization.XmlSerializer xmlSer =
new System.Xml.Serialization.XmlSerializer(typeof(double[][]));
it work perfectly
|
|
|
|
|
Sooorrrrry for the last post but it's wrong
when I write
System.Xml.Serialization.XmlSerializer xmlSer =
new System.Xml.Serialization.XmlSerializer(typeof(double));
It work well (but don't deserialize the things that I want)!
|
|
|
|
|
The problem that you're having there is definitely weird. It sounds like it's unable to locate the dll it uses for XML serialization. I tried it on my machine and didn't have any problems. Here's the code I used:
double[][] d = new double[2][];
for (int i = 0; i < 2; i++)
{
d[i] = new double[2];
for (int j = 0; j < 2; j++)
d[i][j] = i + j;
}
XmlSerializer xs = new XmlSerializer(typeof(double[][]));
xs.Serialize(Console.Out, d);
This actually did serialize my array without a problem. I would say you might want to try searching the KB articles on Microsoft to see if anyone else has that error. If that doesn't turn up anything, you might want to find someone with an MSDN subscription that can report the error for you.
Logifusion[^]
|
|
|
|
|
As far as I know, you can only serialize 1 dimensional array.
If you want to serialize more than 1 dimensional array, try to use BinaryFormatter.
Example:
double[][] d = new double[2][];
for(int i = 0; i < d.Length; i++)
{
d[i] = new double[2];
}
BinaryFormatter b = new BinaryFormatter();
using(FileStream fs = new FileStream("test.bin", FileMode.Create))
{
b.Serialize(fs, d);
}
|
|
|
|
|
When you do XmlSerialization you cannot just do something like what you are trying to do. If , however, you defined something like this:
[Serializable]
public class DoubleArray
{
double[,] data;
[XmlArray(typeof(double[,])]
public double[,] Data
{
get{}
set{}
}
}
public class UseStuff
{
DoubleArray array = new DoubleArray();
...
XmlSerializer ser = new XmlSerializer(typeof(DoubleArray));
using ( FileStream stream = File.Create(path) )
{
ser.Serialize(stream, array);
}
}
That is the correct way to serialize that data.
|
|
|
|
|
Hi,
Iam new to c# , can any one help me how to make a dragable window inside a mainwindow similar to the errorlist or output box inside vs.net.
Thankyou
Regards
Praveen
|
|
|
|
|
Hi,
there is no inbuilt support for this. Either you have to buy a component (e.g. DevExpress) or have a look at this free component.[^]
|
|
|
|
|
how can i set the attribute of file or directory that everyone can write in NTSF?
|
|
|
|
|
Good day
I am new to C# and .NET. I am playing around to get the basics under my belt. I am stuck. I am creating a project the makes use of a Data Layer, Business layer, and a presentation layer. I am having problems retrieving data from the database(SQL Server). What the program can do at the moment is it can retrieve data from the DB and display it into a listview. But what I am struggling with is once you click on a person
in the first listview, the details for that person should appear in the other listview. I have having problems. I make use of interfaces as well.
Please assist.
Thanks
J9
|
|
|
|
|
Providing some code that you are doing would really help for pinpointing the problem. But here is a highlevel design I would implement:
Windows Form -- class that contains the two listboxes
the select event in the main box causes a lookup
and populate of the second listbox.
'business layer' -- exposes general methods for the form.
public PrimaryData GetPrimaryList(string key)
{
return GetPrimaryDataObjects(key, connection);
}
public SecondaryList GetSecondaryList(string key)
{
return GetSecondaryDataObjects(key, connection);
}
Finally the datalayer -- gets data and exposes the two methods used above.
Now, if you have problems then the first thing to do is begin doing breakpoints and run in Debug mode. I'd set a breakpoint on the event of selecting an item in the primary list. Single step (F11) through everything and validate you are actually passing around the data you think you are passing around. Do QuickWatch on specific items and verify you have everything you should.
Once you have a point where you've constructed a query, QuickWatch that and then copy it into Query Analyzer and make sure that the query actually works when you manually point it at your database.
Those are just the first two steps I'd take in getting the answer to my own qauestion.
|
|
|
|
|
Hi Everyone,
I am new to c# , can any one help me how to move around a tool strip During runtime, using the grip.
Thank you,
Regards
Praveen
|
|
|
|
|
I'm using C# in VS2005 to do some XPath queries. I've created my XPath statement using XMLSpy and it is something like:
//Unit/concat(productCode, ":", serialNumber)
I also tried with string-join, but I get the same error when I try it in my C# code:
Unhandled Exception: System.Xml.XPath.XPathException: '//Unit/concat(productCode,":",serialNumber)' has an invalid token.
Surely the concat function exists in the .net xpath library, am I doing something wrong?
The code around this is the standard routine:
xpathDoc = new XPathDocument(Filename);
xpathNav = xpathDoc.CreateNavigator();
xpathIter = xpathNav.Select(XPathString);
- loop through the results etc -
I hope someone has some pointers as to what could be wrong
Thanks
|
|
|
|
|
Try this code for xpath query
//Unit[concat(productCode,":",serialNumber)]
Put your xml file and the code where you assign value to XPathString, So that someone could help you.
|
|
|
|
|
Thanks for the reply
This still says 'invalid token'.
Also... The result of 'concat(productCode,":"serialNumber)' is what I want returned, for example, I want the result of my xpath query to be a list of records like:
PCP4:123
macIntel:321
PDAIPAQ:456
The 'concat' function is the part I think is the bit that's wrong... for some reason I think it's not in the MS VS2005 XPath library... could this be possible?
|
|
|
|
|
i am using DtaeTime variable in my codes and adding
some days to it but getting error
"Ticks must be between DateTime.MaxValue.Ticks and DateTime.MinValue.Ticks"
any one can help out
rahul
-- modified at 4:36 Tuesday 20th June, 2006
|
|
|
|
|
What is the code your are using?
|
|
|
|
|
The first point I'd give you is to read Chris' post at the top of the forum on 'How to get your questions answered'. This is a horrible question.
As to an answer, the DateTime object exposes various Add() functions. Your use of it is being interpretted as passing an add of Ticks to the date. (Probably the worst kind of increment anyone could do to a DateTime object)
So your problem is exactly what your error message says: you are passing either too small or too large a number of Ticks. (DUH)
You have asked for help but you never mention just what the
H-E-double-hocky-sticks you are actually trying to do!!!!! For that reason alone I've rated your question as 1 because your question is so stupid.
So if you want to add a certain number of hours or days to a date, then what you would do is : date.Add(new DateTime(0, 12, 0)) In this example you are adding 12 hours to the day in your variable. But, of course, if you just pay attention to your Intellisense, then you would discover that it actually TELLS YOU what to do.
|
|
|
|
|
thanks for ur reply & advice
this much i have understood that this error is coming becouse
some where the datetime objects minimum range i.e 01/01/0001 or maximum
range i.e 31/12/9999 is crossed,but i want to confirm only one thing
that can this type of error happens due to any other reason or this is
the only possible cause.
rahul
|
|
|
|
|
The best way to determine the cause of the error is to debug your code and see what the values are -- the current DateTime value and the value you are trying to add to it. If you are running VS 2005, the debug exception also has a link providing more detailed information on the web.
|
|
|
|
|
Hi
I am using an OpenFileDialog to select a number of files and I change their filenames programmatically by using the FileInfo MoveTo() method. Is there a way of getting the date that the file was last modified as well. I would like to change the filename as in the following example:
Old name = StaffList.doc
New name = StaffList060612.doc
where 060612 is the date that it was modified.
Kobus
|
|
|
|
|
I think FileInfo.LastAccessTime[^] is what you're looking for.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Perfect, exactly what I was looking for.
Thank you.
Kobus
|
|
|
|