Suspect error using RichTextBox Class in server code

E

Eric

Using the 1.1 framework. We are using a newly created instance of a
RichTextBox Class in our server code to manipulate RTF that is stored
in the database. To clarify, we are not using or attempting to use
this class in the aspx page that calls the code, nor is the 'using
System.Windows.Forms' referenced in any of the aspx pages. The first
client using this software has been experiencing an error that we
cannot reproduce in-house. The error occurs intermittently anywhere
after 2-4 days of use, so it is not something reproducible on demand.
The fix is to restart IIS and on a couple of occasions a restart of
the server was necessary. The error is being trapped in code and
returned as string to the user which displays on the aspx page so it
is not an unhandled exception with a dump of the stack trace. The
error message is 'Error creating window handle". Once one user
receives this error all users receive the same error when trying to
perform the same operation. I am not 100% sure that the RichTextBox
code is what is causing the error but based on the message involved it
is my best guess. Here is a code snipit that shows how we are using
the RichTextBox.



string strFreeRTF = drRow["FRTF"].ToString().Trim();
string strTempRTF = drRow["TMPLTRTF"].ToString().Trim();
RichTextBox rtfFree = new RichTextBox();
rtfFree.Rtf = strFreeRTF; //prevents null reference
RichTextBox rtfTemp = new RichTextBox();
rtfTemp.Rtf = strTempRTF;
if(rtfTemp.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfTemp.SelectAll();
rtfTemp.Copy();
rtfFree.Paste();
}
if(strCodedCharting.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfFree.AppendText(strCodedCharting);
}

if(drChart["SUMMARY"].ToString() != "")
{
if(rtfFree.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
}
rtfFree.AppendText(drRow["SMRYTXT"].ToString());
}
if(rtfFree.Text != "")
strRet = rtfFree.Rtf;
return strRet;

The code performs what it is designed to do but obviously we need to
track down why the error occurs.

Does anyone have information that might assist with troubleshooting
this problem. Thanks
 
B

bruce barker

using winform controls are not supported by aspx pages. they require a
window handle to perform correctly, and system services like iis and
asp.net, do not have permission to create a window handle as they need
access to the desktop.

you might get away with it if the console is alway logged on the server, and
you gave permission. you still run the risk, that if the control pop's up a
dialog box (say for en error), your asp.net thread will be blocked until
some goes to the console and responds to the dialogbox.

this is very poor design, and you should look at replacing the rtf control
as soon as possible.

-- bruce (sqlwork.com)



Eric said:
Using the 1.1 framework. We are using a newly created instance of a
RichTextBox Class in our server code to manipulate RTF that is stored
in the database. To clarify, we are not using or attempting to use
this class in the aspx page that calls the code, nor is the 'using
System.Windows.Forms' referenced in any of the aspx pages. The first
client using this software has been experiencing an error that we
cannot reproduce in-house. The error occurs intermittently anywhere
after 2-4 days of use, so it is not something reproducible on demand.
The fix is to restart IIS and on a couple of occasions a restart of
the server was necessary. The error is being trapped in code and
returned as string to the user which displays on the aspx page so it
is not an unhandled exception with a dump of the stack trace. The
error message is 'Error creating window handle". Once one user
receives this error all users receive the same error when trying to
perform the same operation. I am not 100% sure that the RichTextBox
code is what is causing the error but based on the message involved it
is my best guess. Here is a code snipit that shows how we are using
the RichTextBox.



string strFreeRTF = drRow["FRTF"].ToString().Trim();
string strTempRTF = drRow["TMPLTRTF"].ToString().Trim();
RichTextBox rtfFree = new RichTextBox();
rtfFree.Rtf = strFreeRTF; //prevents null reference
RichTextBox rtfTemp = new RichTextBox();
rtfTemp.Rtf = strTempRTF;
if(rtfTemp.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfTemp.SelectAll();
rtfTemp.Copy();
rtfFree.Paste();
}
if(strCodedCharting.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfFree.AppendText(strCodedCharting);
}

if(drChart["SUMMARY"].ToString() != "")
{
if(rtfFree.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
}
rtfFree.AppendText(drRow["SMRYTXT"].ToString());
}
if(rtfFree.Text != "")
strRet = rtfFree.Rtf;
return strRet;

The code performs what it is designed to do but obviously we need to
track down why the error occurs.

Does anyone have information that might assist with troubleshooting
this problem. Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top