473,714 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Exception in default Hashtable constructor

While running some long term tests on our Broadcast SDK one of our
thread dropped out because an exception had been thrown:

Exception: System.Argument OutOfRangeExcep tion
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collecti ons.Hashtable.. ctor(Int32 capacity, Single
loadFactor, IHashCodeProvid er hcp, IComparer comparer)
at System.Collecti ons.Hashtable.. ctor()
at Codestuff.Harth ill.Sources.Bas eSource.ReadHea ders(Stream s)
at Codestuff.Harth ill.Sources.Bas eSource.ReadJpe g(Stream str, Byte[]
boundaryBytes)
at Codestuff.Harth ill.Sources.Liv eSource.VideoSt reamProc()

Now, correct me if I'm wrong but surely if I'm calling the default
constructor on such a common Framework class, I shouldn't expect to get
an Argument exception...

Has anyone else seen this or know what could be causing it?

Dec 5 '05 #1
9 4640
Nick,

When you use a default hashtable constructor, it assumes a load factor
of 1. However, because it uses a float for that, it might not be exactly 1
(even though it is baked into the code as 1).

This could be the result of your exception. Unfortunately, reproducing
it consistently will be extremely difficult. This is one of the dangers of
using floats...

Perhaps what you could do is create a wrapper which will catch that
exception, and retry the creation of the hashtable.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Nick Vaughan" <ni**@codestuff .net> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
While running some long term tests on our Broadcast SDK one of our
thread dropped out because an exception had been thrown:

Exception: System.Argument OutOfRangeExcep tion
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collecti ons.Hashtable.. ctor(Int32 capacity, Single
loadFactor, IHashCodeProvid er hcp, IComparer comparer)
at System.Collecti ons.Hashtable.. ctor()
at Codestuff.Harth ill.Sources.Bas eSource.ReadHea ders(Stream s)
at Codestuff.Harth ill.Sources.Bas eSource.ReadJpe g(Stream str, Byte[]
boundaryBytes)
at Codestuff.Harth ill.Sources.Liv eSource.VideoSt reamProc()

Now, correct me if I'm wrong but surely if I'm calling the default
constructor on such a common Framework class, I shouldn't expect to get
an Argument exception...

Has anyone else seen this or know what could be causing it?

Dec 5 '05 #2
Hi Nicholas,

Thanks for your reply.

How can a float which is 1.0 not always be 1.0? I would have though
it's a constant value.

Are you suggesting that once in a while, this constructor is just going
to fling an exception? That sounds like quite a serious issue doesn't
it?

Could it be that the default constructor tries to modify the loadfactor
based on the amount of available memory?

Am I required to put a try-catch block around every call to 'new
Hashtable( )' ??

Cheers,

Nick.

Dec 5 '05 #3
Nicholas Paldino [.NET/C# MVP] wrote:
When you use a default hashtable constructor, it assumes a load factor
of 1. However, because it uses a float for that, it might not be exactly 1
(even though it is baked into the code as 1).


If it's baked into the code as 1, it should be exactly 1. 1 is exactly
representable in all the various floating point formats .NET has.

I can't think of any floating point conversion that would corrupt that,
or give a false comparison with another value of exactly 1.

This is very odd...

Jon

Dec 5 '05 #4
Jon,

How about a cast from double to float?

When looking at the code in reflector, it's the only thing I could think
of that would cause this.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Nicholas Paldino [.NET/C# MVP] wrote:
When you use a default hashtable constructor, it assumes a load
factor
of 1. However, because it uses a float for that, it might not be exactly
1
(even though it is baked into the code as 1).


If it's baked into the code as 1, it should be exactly 1. 1 is exactly
representable in all the various floating point formats .NET has.

I can't think of any floating point conversion that would corrupt that,
or give a false comparison with another value of exactly 1.

This is very odd...

Jon

Dec 5 '05 #5
Nicholas Paldino [.NET/C# MVP] wrote:
How about a cast from double to float?
Certainly wouldn't change 1.0 to anything else, because it's exactly
representable in both forms. At least, it would only break things if
something was seriously broken in the conversion :)

(None of the 80-bit to 32/64-bit conversions should break 1.0 either.
It's one of the simplest bit patterns for floating point numbers that
you can get...)
When looking at the code in reflector, it's the only thing I could think
of that would cause this.


That's reasonable - I just can't see how it would possibly fail.

I suspect either a hardware failure or a problem deep inside the CLR...

Jon

Dec 5 '05 #6
Well, it just happened again this evening:

Exception: System.Argument OutOfRangeExcep tion
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collecti ons.Hashtable.. ctor(Int32 capacity, Single
loadFactor, IHashCodeProvid er hcp, IComparer comparer)
at System.Collecti ons.Hashtable.. ctor()
at Codestuff.Harth ill.Sources.Bas eSource.ReadHea ders(Stream s)
at Codestuff.Harth ill.Sources.Bas eSource.ReadJpe g(Stream str, Byte[]
boundaryBytes)
at Codestuff.Harth ill.Sources.Liv eSource.VideoSt reamProc()

To be honest, I'm going to refactor this code anyway as I don't really
like the idea of create a new hashtable 30 times a second!! However,
its an interesting bug with the framework I think. Its unlikely to be
hardware as it has happened on 2 separate and quite different machines.

Hopefully someone will be able to track this one down and fix it!!

Thanks for your responses people.

Nick.

Dec 6 '05 #7
This is a long shot, but does it happen only on one particular machine?
Have you tried running a utility to thrash that machine's memory to
make sure that it's OK? One of the guys in my office swears that these
oddball bugs are occasionally the result of bad memory.

Dec 6 '05 #8
Nick Vaughan wrote:
Well, it just happened again this evening:

Exception: System.Argument OutOfRangeExcep tion
Message: Load factor needs to be between 0.1 and 1.
Parameter name: loadFactor
Source: mscorlib
at System.Collecti ons.Hashtable.. ctor(Int32 capacity, Single
loadFactor, IHashCodeProvid er hcp, IComparer comparer)
at System.Collecti ons.Hashtable.. ctor()
at Codestuff.Harth ill.Sources.Bas eSource.ReadHea ders(Stream s)
at Codestuff.Harth ill.Sources.Bas eSource.ReadJpe g(Stream str, Byte[]
boundaryBytes)
at Codestuff.Harth ill.Sources.Liv eSource.VideoSt reamProc()

To be honest, I'm going to refactor this code anyway as I don't really
like the idea of create a new hashtable 30 times a second!!
Well, I wouldn't worry about that. 30 new hashtables in a second is
barely going to catc your computer's attention. I very quick
micro-benchmark I just wrote showed my desktop being able to create
about 8 *million* new hashtables in a second. Go for the simplest code
which works and which doesn't give you a *definite* performance
problem.
However, its an interesting bug with the framework I think. Its unlikely to be
hardware as it has happened on 2 separate and quite different machines.


This is an odd suggestion, but are these machines by any chance using
the same anti-virus software? Try disabling the AV software, reboot,
and try again. I've seen some AV software changing the floating point
mode of a computer, and that can have some odd effects. I can't see why
it would be a problem here, but it's possible. If that's not it, could
you tell us anything else which the two computers have in common?

Jon

Dec 6 '05 #9
They are both running the same AV software, I'll run the tests again
tonight with it turned off and report back. There does seem to be
something happening with the network around the time of the exception
being thrown so this could tie in.

Cheers,

nick.

Dec 6 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3499
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? Is this because there could be an exception thrown when the code creates a std::exception? I would assume that is not the case. However, if I want to create a new exception class, derived from std::exception (say MyException) then how can I...
4
1295
by: alkee.na | last post by:
Hey, Here's a sample code you can easily guess the result. <result 1> #include <iostream> using namespace std; class AA { public: AA() { cout<<"AA();"<<endl; }
3
3168
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on the server (W2K3) it throws an exception. It only seems to happen when serializing/deserializing _arrays_ of a type. If I just serialize/deserialize one instance, it works fine. The exception I get is: (sorry for the word wrapping.)...
11
1960
by: Lloyd Dupont | last post by:
(not I use 2.0, so new return a "normal" pointer and gcnew return a managed one, my question below regarding new concern plain standart C++ allocator) - if I use the default new operator, are all the instance variable initialize to NULL / 0 ? - if there is not enough memory what happend with new ? does it return NULL or throw an exception? - if new throw a native C++ exception what happen in Managed C++ ?! - if there is an exception in...
3
3405
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is to be supplied to the exception constructor, the default constructor should
12
2267
by: StephQ | last post by:
I have a class Bounds with two constructors: class Bounds { private: list<SegmentupperLinearSpline; // Upper bound. list<SegmentlowerLinearSpline; // Lower bound. ....
3
5429
by: hiddenhippo | last post by:
Hi, I have a class which contains all my constant values such as; public static readonly string strStringOps = {"Equals","Not Equals","Contains"}; The above nicely assigns the values into the string array. However I'm looking for a way of achieving the same results whilst using a hashtable; for example
10
2065
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
6
3338
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem I discovered first a workaround, then the real cause of the problem. I would like to understand why what I am doing is frowned upon by Visual Studio and how to do this properly. My application is in one solution; supporting libraries including...
0
8802
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4726
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2111
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.