|
I'm having a problem with the XmlSerializer in .NET 2.0 (I never had this problem in 1.1).
I have a class which currently contains only a bool property and a string property that I'm trying to serialize using the XmlSerializer. My Serialization code is simple and I've used it 100 times before:
XmlSerializer xout = new XmlSerializer(typeof(MyClass));
StreamWriter sout = new StreamWriter(fname);
xout.Serialize(sout, this);
sout.Close();
The problem is that as soon as I try and execute the first line the program hangs. I even tried to use [XmlIgnore] attributes on both of my properties to try and track down if one of them is causing a problem but that doesn't even work. I'm totally mystified. My class has two public properties (bool and string), two private fields (bool and string) a default parameterless constructor and two methods (one to serialize and one to deserialize). What could possibly be wrong?
|
|
|
|
|
Jon, try replacing typeof(MyClass) with new(MyClass)MyClass().GetType() and see if that helps?
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
-- modified at 9:49 Sunday 30th April, 2006
|
|
|
|
|
|
|
Thanks for the suggestion. I tried this.GetType() instead of typeof(MyClass) and that didn't seem to work either. I can't figure out what it's got against my class?
|
|
|
|
|
|
The XmlSerializer always worked for me in .NET 1.1 (or at least I could eventually get it working after figuring out all the tiny problems that tended to cause it to throw exceptions). This is the first time I've tried it in .NET 2.0 and it isn't even throwing an exception, it just hangs.
|
|
|
|
|
I'm using RNGCrytpoServiceProvider to generate a 4-byte random number, and then dividing that by Int32.MaxValue to get a Double between 0 and 1.0. Is the resulting number still random, or has it been compromised? Is there a better way to do this?
Jon Sagara
Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman.
My Site | My Blog | My Articles
|
|
|
|
|
There is also Random.NextDouble of course!
|
|
|
|
|
I'd prefer to use RNGCryptoServiceProvider, but if the way I'm performing the calculation compromises the number, I may as well use System.Random.NextDouble.
Jon Sagara
Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman.
My Site | My Blog | My Articles
|
|
|
|
|
I'm no expert but:
1. From a mathematical point of view: No as you are dividing just by a factor.
2. From a technical point of view: Yes, as a conversion to double normally also means that some rouding errors are introduced which MIGHT cause trouble (in means of security).
|
|
|
|
|
If you just want a normal random number you should use the Random class.
The random generators in the encryption engines is for creating encryption keys, as the Random class is way too predictable for that. Of course that means that the algorithm is more complex and therefore more time consuming.
---
b { font-weight: normal; }
|
|
|
|
|
The better way would be to use the BitConverter or go stylish
unsafe
{
fixed (int* p = &randomint)
{
return (float) *p;
}
}
|
|
|
|
|
Hi,
I would appreciate if somebody could post some links (or sample code) to transform a ADO resultset to string using XSL.
Thanks.
|
|
|
|
|
Prashant, see listing 2 in the .zip file on this[^] page. You don't need to register/subscribe in order to download the file.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I have a file that is being written to using stream writer. The file is written in frequent, random intervals. If I were to use a seperate application to grab a copy of this file (using File.Copy), would there be a chance the two applications would collide, while trying to perform operations on the same file? Or is the File.Copy method independant of whether the file is in use.. meaning I'd get the most recent copy from the last stream writer update?
Any help would be appreciated!
|
|
|
|
|
cmarcus wrote: have a file that is being written to using stream writer. The file is written in frequent, random intervals. If I were to use a seperate application to grab a copy of this file (using File.Copy), would there be a chance the two applications would collide, while trying to perform operations on the same file?
Assuming the stream writer has only locked the file for write operations (i.e. read operations are still allowed), then there should be no problem with the other application using File.Copy. It is essentially only reading the file.
cmarcus wrote: Or is the File.Copy method independant of whether the file is in use.. meaning I'd get the most recent copy from the last stream writer update?
It will get the version that was last updated by stream writer as a result of flushing the buffer.
|
|
|
|
|
pleas i want to know how to record a voice from the mic and play it back when i need
some one told me to try NBass i try it and i got these problem
====================
An unhandled exception of type 'System.NullReferenceException' occurred in nbass.dll
Additional information: Object reference not set to an instance of an object.
====================
it dosenot work i don't know why
all i need is code to record and play
simple code
|
|
|
|
|
|
i don't know what information you need
tell me like what ?
|
|
|
|
|
Such as the piece of code that causes the NullReferenceException to be thrown.
|
|
|
|
|
Hi there,
I there a way to set the DateTime to always return things in Univeral Time? looks like its default kind is local... and I can't see any static method to set it to always give me the universal time value. Right now, I have to do a .ToUniversalTime() everytime I try to get the date time value...
Thanks for the help,
~Rafferty
|
|
|
|
|
I'm a little confused on how you're using the DateTime. Finally, in .Net 2.0 they fixed DateTime so it knows whether it's local or universal. If you want to create a new DateTime, there's a constructor that takes the DateTimeKind enum. If you're always pulling the current date, you can use UtcNow.
www.logifusion.com
|
|
|
|
|
ahhh... okay so I really have to change all my code. I was declaring everything without specifying the kind, and somehow when I display it in the screen i'm working on, everything's in local.
a few more questions, i can't find these in the help:
- when you do a DateTime.Parse(...), what's the DateTimeKind set to? Unspecified?
- what happens if you Compare a local and an unspecified DateTime? does it ignore the kinds or does it first convert the unspecified date time to something else?
Thanks!
|
|
|
|
|
Good questions. Unspecified is what it will most likely be when you parse. But you can also use the SpecifyKind method.
<br />
DateTime dt = DateTime.SpecifyKind(DateTime.Parse("some string"), DateTimeKind.Local)<br />
Comparison is a tricky one as well. DateTime has an Int64 buried underneath it that represents the ticks that identify the time. There were two bits left over of the 64 that were not used, so in .Net 2.0 they decided to use them for the DateTimeKind enum. I imagine an equals should check the kind since it will probably just compare the two integers. Compare might do this as well. MSDN just tells you to make sure they're both in the same time zone.
www.logifusion.com
|
|
|
|