Showing posts with label least. Show all posts
Showing posts with label least. Show all posts

Thursday, March 22, 2012

System.ObjectDisposedException - REALLY NEED HELP !

Hi !

My website breakdown at least 20 times per day with a
System.ObjectDisposedException.

The only information available are those given by the httpmodule treating
the unhandledexception causing breakdown. Here are these information :

Type de l'vnement : Erreur
Source de l'vnement : ASP.NET 2.0.50727.0
Catgorie de l'vnement : Aucun
ID de l'vnement : 0
Date : 4/12/2007
Heure : 13:36:00
Utilisateur : N/A
Ordinateur : T04
Description :
La description pour l'ID d'vnement ( 0 ) dans la source (ASP.NET
2.0.50727.0) est introuvable. L'ordinateur local n'a peut-tre pas les
informations de Registre ou les librairies requises pour afficher les
messages manant d'un ordinateur distant. Vous pourrez peut-tre utiliser
l'option /AUXSOURCE= pour rcuprer cette description. Reportez-vous aux
rubriques Aide et support pour plus de dtails. Les informations suivantes
font partie de l'vnement :

UnhandledException logged by UnhandledExceptionModule.dll:

appId=/LM/W3SVC/1984782886/Root

type=System.ObjectDisposedException

message=Le handle scuris a t ferm

stack=
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
?.Finalize()

There is no trace from my webapplication in the stacktrace. So it's
impossible for me to find where is located the problem in my webapplication.

Ant idea to locate the origin of the problem would be great !

--
Bernard
bernard.borsu@dotnet.itags.org.odysseos.netdeploy a debug build, and you will get a stack trace.

-- bruce (sqlwork.com)

"Bernard Borsu" wrote:

Quote:

Originally Posted by

Hi !
>
My website breakdown at least 20 times per day with a
System.ObjectDisposedException.
>
The only information available are those given by the httpmodule treating
the unhandledexception causing breakdown. Here are these information :
>
Type de l'événement : Erreur
Source de l'événement : ASP.NET 2.0.50727.0
Catégorie de l'événement : Aucun
ID de l'événement : 0
Date : 4/12/2007
Heure : 13:36:00
Utilisateur : N/A
Ordinateur : T04
Description :
La description pour l'ID d'événement ( 0 ) dans la source (ASP.NET
2.0.50727.0) est introuvable. L'ordinateur local n'a peut-être pas les
informations de Registre ou les librairies requises pour afficher les
messages émanant d'un ordinateur distant. Vous pourrez peut-être utiliser
l'option /AUXSOURCE= pour récupérer cette description. Reportez-vous aux
rubriques Aide et support pour plus de détails. Les informations suivantes
font partie de l'événement :
>
UnhandledException logged by UnhandledExceptionModule.dll:
>
appId=/LM/W3SVC/1984782886/Root
>
type=System.ObjectDisposedException
>
message=Le handle sécurisé a été fermé
>
stack=
* System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
socketHandle, Int32 how)
* System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
* ?.Finalize()
>
There is no trace from my webapplication in the stacktrace. So it's
impossible for me to find where is located the problem in my webapplication.
>
Ant idea to locate the origin of the problem would be great !
>
--
Bernard
bernard.borsu@.odysseos.net
>
>
>


Hi !

I've think i've already deployed a debug version. In VS2005, i've selected
debug in the configuration manager before generating my web application. All
pdb files are present on the bin directory of the website.

Did i missed something in generating a debug version ?

"bruce barker (sqlwork.com)"
<brucebarkersqlworkcom@.discussions.microsoft.coma crit dans le message de
news: F0AA7A5E-A8B9-49F3-8678-93E20B758429@.microsoft.com...

Quote:

Originally Posted by

deploy a debug build, and you will get a stack trace.
>
-- bruce (sqlwork.com)
>
>
"Bernard Borsu" wrote:
>

Quote:

Originally Posted by

>Hi !
>>
>My website breakdown at least 20 times per day with a
>System.ObjectDisposedException.
>>
>The only information available are those given by the httpmodule treating
>the unhandledexception causing breakdown. Here are these information :
>>
>Type de l'vnement : Erreur
>Source de l'vnement : ASP.NET 2.0.50727.0
>Catgorie de l'vnement : Aucun
>ID de l'vnement : 0
>Date : 4/12/2007
>Heure : 13:36:00
>Utilisateur : N/A
>Ordinateur : T04
>Description :
>La description pour l'ID d'vnement ( 0 ) dans la source (ASP.NET
>2.0.50727.0) est introuvable. L'ordinateur local n'a peut-tre pas les
>informations de Registre ou les librairies requises pour afficher les
>messages manant d'un ordinateur distant. Vous pourrez peut-tre utiliser
>l'option /AUXSOURCE= pour rcuprer cette description. Reportez-vous aux
>rubriques Aide et support pour plus de dtails. Les informations
>suivantes
>font partie de l'vnement :
>>
>UnhandledException logged by UnhandledExceptionModule.dll:
>>
>appId=/LM/W3SVC/1984782886/Root
>>
>type=System.ObjectDisposedException
>>
>message=Le handle scuris a t ferm
>>
>stack=
> System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown( SafeCloseSocket
>socketHandle, Int32 how)
> System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
> ?.Finalize()
>>
>There is no trace from my webapplication in the stacktrace. So it's
>impossible for me to find where is located the problem in my
>webapplication.
>>
>Ant idea to locate the origin of the problem would be great !
>>
>--
>Bernard
>bernard.borsu@.odysseos.net
>>
>>
>>

System.ObjectDisposedException - REALLY NEED HELP !

Hi !
My website breakdown at least 20 times per day with a
System.ObjectDisposedException.
The only information available are those given by the httpmodule treating
the unhandledexception causing breakdown. Here are these information :
Type de l'vnement : Erreur
Source de l'vnement : ASP.NET 2.0.50727.0
Catgorie de l'vnement : Aucun
ID de l'vnement : 0
Date : 4/12/2007
Heure : 13:36:00
Utilisateur : N/A
Ordinateur : T04
Description :
La description pour l'ID d'vnement ( 0 ) dans la source (ASP.NET
2.0.50727.0) est introuvable. L'ordinateur local n'a peut-tre pas les
informations de Registre ou les librairies requises pour afficher les
messages manant d'un ordinateur distant. Vous pourrez peut-tre utiliser
l'option /AUXSOURCE= pour rcuprer cette description. Reportez-vous aux
rubriques Aide et support pour plus de dtails. Les informations suivantes
font partie de l'vnement :
UnhandledException logged by UnhandledExceptionModule.dll:
appId=/LM/W3SVC/1984782886/Root
type=System.ObjectDisposedException
message=Le handle scuris a t ferm
stack=
System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket
socketHandle, Int32 how)
System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
?.Finalize()
There is no trace from my webapplication in the stacktrace. So it's
impossible for me to find where is located the problem in my webapplication.
Ant idea to locate the origin of the problem would be great !
Bernard
bernard.borsu@dotnet.itags.org.odysseos.netdeploy a debug build, and you will get a stack trace.
-- bruce (sqlwork.com)
"Bernard Borsu" wrote:

> Hi !
> My website breakdown at least 20 times per day with a
> System.ObjectDisposedException.
> The only information available are those given by the httpmodule treating
> the unhandledexception causing breakdown. Here are these information :
> Type de l'événement : Erreur
> Source de l'événement : ASP.NET 2.0.50727.0
> Catégorie de l'événement : Aucun
> ID de l'événement : 0
> Date : 4/12/2007
> Heure : 13:36:00
> Utilisateur : N/A
> Ordinateur : T04
> Description :
> La description pour l'ID d'événement ( 0 ) dans la source (ASP.NET
> 2.0.50727.0) est introuvable. L'ordinateur local n'a peut-être pas les
> informations de Registre ou les librairies requises pour afficher les
> messages émanant d'un ordinateur distant. Vous pourrez peut-être utilise
r
> l'option /AUXSOURCE= pour récupérer cette description. Reportez-vous aux
> rubriques Aide et support pour plus de détails. Les informations suivante
s
> font partie de l'événement :
> UnhandledException logged by UnhandledExceptionModule.dll:
> appId=/LM/W3SVC/1984782886/Root
> type=System.ObjectDisposedException
> message=Le handle sécurisé a été fermé
> stack=
> _ System.Net.UnsafeNclNativeMethods.OSSOCK.shutdown(SafeCloseSocket
> socketHandle, Int32 how)
> _ System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
> _ ?.Finalize()
> There is no trace from my webapplication in the stacktrace. So it's
> impossible for me to find where is located the problem in my webapplicatio
n.
> Ant idea to locate the origin of the problem would be great !
> --
> Bernard
> bernard.borsu@.odysseos.net
>
>
Hi !
I've think i've already deployed a debug version. In VS2005, i've selected
debug in the configuration manager before generating my web application. All
pdb files are present on the bin directory of the website.
Did i missed something in generating a debug version ?
"bruce barker (sqlwork.com)"
<brucebarkersqlworkcom@.discussions.microsoft.com> a crit dans le message de
news: F0AA7A5E-A8B9-49F3-8678-93E20B758429@.microsoft.com...
> deploy a debug build, and you will get a stack trace.
> -- bruce (sqlwork.com)
>
> "Bernard Borsu" wrote:
>

System.Random duplicate numbers problem

I want to generate random numbers from Min Limit to Max limit, but I always get one duplicate number , at least.

I use this code:

ArrayList generatedNumbers = new ArrayList();

int MinLimit = 0;
int MaxLimit = 10;
Random R = new Random();

int randomNum;
numOfGenerated = 7;

for(int i=0;i<numOfGenerated;i++)
{
randomNum= R.Next(MinLimit,MaxLimit);
generatedNumbers.Add(randomNum);
}

Any idea how to solve the problem?If you generate seven random numbers between 0 and 10, it is very very likely that you will get duplicate numbers (easy to calculate, by the way).
If what you want is to extract the numbers only once and at random, you can use a little trick, which would be to mark the numbers you've already chosen.
Here's some code (not checked, but you should see the spirit):


ArrayList generatedNumbers = new ArrayList();

int MinLimit = 0;
int MaxLimit = 10;
Random R = new Random();

int randomNum;
numOfGenerated = 7;

bool[] alreadyUsed = new bool[MaxLimit];

if (numOfGenerated > MaxLimit) {
throw new Exception("Can't extract that many numbers");
}

for(int i=0;i<numOfGenerated;i++)
{
randomNum= R.Next(MinLimit,MaxLimit);
while (alreadyUsed[randomNum]) {
randomNum = (randomNum + 1) % MaxLimit;
}
generatedNumbers.Add(randomNum);
}

If finds the nearest available number after the randomly chosen position. I wouldn't guarantee this is purely random, though, as this probably introduces some artefacts...
"I wouldn't guarantee this is purely random, though, as this probably introduces some artefacts...
"

Yes, I always get same numbers :-)
I don't quite understand the logic behind Bertrand's script (it doesn't appear to turn any boolean value to true, which is how it would indicate that the number is already present and also adding 1 and then finding the modulus??), however I think the major flaw is your logic and not the random method. Keeping the range of possible random numbers the same, or very close to, the number of numbers that you want to store will always produce duplicates. For example:

If you have an array for two numbers and only allow the random numbers to be either 1 or 2, the result could be:

1,1
1,2
2,1
2,2

which means that there is a 50% probability that there will be duplicates.

Increasing the random number range to 10 and the array to 7 does, obviously, reduce that probability (slightly), however it is still highly likely that there will be duplicates.

To solve this you could either replace the for loop in Bertrand's script with:

for(int i=0;i<numOfGenerated;i++) {

randomNum = R.Next(MinLimit,MaxLimit);
if ( !alreadyUsed[randomNum] ) {

generatedNumbers.Add(randomNum);
alreadyUsed[randomNum] = true;
}
}

or increase the range of possible random numbers
I have allready added part
"alreadyUsed[randomNum] = true;" before I posted my previous comment.

If I put yoour code, Steven, I'll not get same number of random numbers for every load.

Bertrand's script works welll but it get's same number's in diferent combination.
I think it is a result of small number of posible combinations. This is my code:

Random R = new Random((int)System.DateTime.Now.Ticks);

int MinLimit = 0;
int MaxLimit = numOfGenerated;

bool[] alreadyUsed = new bool[MaxLimit];

for(int i=0;i<numOfGenerated;i++)
{
randomNum = R.Next(MinLimit,MaxLimit);

while (alreadyUsed[randomNum])
{
randomNum = (randomNum + 1) % MaxLimit;
}
alreadyUsed[randomNum] = true;
generatedQuestions.Add(randomNum);
}
You could use a Diffrent approach. If you generate a initial ArrayList with all the numbers and start picking random numbers from it and deleting it from the List

like


public int[] GetRandomNumbers( int minValue, int maxValue, int numCount )
{
int[] randomNumbers = new int[ numCount ];
ArrayList numbers = new ArrayList( maxValue - minValue );
Random rand = new Random();
int index;
for( int i = minValue; i < maxValue; i++ )
numbers.Add( i );

for( int i = 0; i < numCount; i++ )
{
index = rand.Next( numbers.Count );
randomNumbers[ i ] = (int)numbers[ index ];
numbers.RemoveAt( index );
}

return randomNumbers;
}


I had forgotten to set the booleans, but you had figured that out yourself. But do you get the expected results or are you still expecting something different?
As I said. I get expected result, but I get always same numbers with diferent positions combination. I suppose that is a result of small number of possible combinations.
Could be an artefact, too.
A really random algorithm would be to decrement the random interval, and always start from the zero position, like this (pseudo-code):

int max = 10;
int remainingIntegers = max;
bool[] alreadyChosen = new bool[max];
int nbIntegers = 7;
int[] randomNumbers = new int[nbIntegers];
Random rnd = new Random();
for (int i = 0; i < nbIntegers ; i++) {
int random = rnd(0, remainingIntegers);
int index = 0;
for (int j = 0; j < random ; j++) {
while (alreadyChosen[index]) {
index++;
Debug.Assert(index < max);
}
}
randomNumbers[i] = index;
alreadyChosen[index] = true;
}

(not tested)