Localizable + PasswordChar = Handle error

G

Guest

I'm creating a user control that has a handful of controls on it (19 in
total). One of the controls on the UC is a textbox for a user's password, so
I've set the PasswordChar property to "*". I rebuild and all is well.

The problem arises when I have the PasswordChar set, and then try to set
Localizable to True for the UC. If I set Localizable to true and have
PasswordChar set and rebuild, Visual Studio 2005 will then try to reload the
User Control in the designer but will show the message "Error creating window
handle." The only way to fix it is to open the Resx file and remove my
PasswordChar property and rebuild.

I can replicate this every time. Is this a bug in VS 2005? What's going on?
 
G

Guest

Hi Jeff,

Thanks for your reply. I tried doing what you said in a new project and it
worked fine. However, on my original control it continues to happen. Here
is the stack trace available from the designer:

Error creating window handle.
Hide

at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.TextBox.get_PasswordChar()
at System.Windows.Forms.Design.TextBoxDesigner.get_PasswordChar()

I'm aware that I can probably start my user control all over, but I'd rather
not do that unless absolutely necessary. I'd also like an understanding as
to why, exactly, this is happening.

Thanks.

- ryan.
 
J

Jeffrey Tan[MSFT]

Hi Ryan,

Yes, I understand your concern.

It seems that this exception is generated in NativeWindow.CreateHandle
method, while NativeWindow class is trying to create the TextBox control.
Below is the source code of NativeWindow.CreateHandle method:

public virtual void CreateHandle(CreateParams cp)
{
IntSecurity.CreateAnyWindow.Demand();
if (((cp.Style & 0x40000000) != 0x40000000) || (cp.Parent ==
IntPtr.Zero))
{
IntSecurity.TopLevelWindow.Demand();
}
lock (this)
{
this.CheckReleased();
NativeWindow.WindowClass class1 =
NativeWindow.WindowClass.Create(cp.ClassName, cp.ClassStyle);
lock (NativeWindow.createWindowSyncObject)
{
if (this.handle == IntPtr.Zero)
{
class1.targetWindow = this;
IntPtr ptr1 =
UnsafeNativeMethods.GetModuleHandle(null);
IntPtr ptr2 = IntPtr.Zero;
int num1 = 0;
try
{
if ((cp.Caption != null) &&
(cp.Caption.Length > 0x7fff))
{
cp.Caption = cp.Caption.Substring(0,
0x7fff);
}
ptr2 =
UnsafeNativeMethods.CreateWindowEx(cp.ExStyle, class1.windowClassName,
cp.Caption, cp.Style, cp.X, cp.Y, cp.Width, cp.Height, new HandleRef(cp,
cp.Parent), NativeMethods.NullHandleRef, new HandleRef(null, ptr1),
cp.Param);
num1 = Marshal.GetLastWin32Error();
}
catch (NullReferenceException exception1)
{
throw new
OutOfMemoryException(SR.GetString("ErrorCreatingHandle"), exception1);
}
class1.targetWindow = null;
if (ptr2 == IntPtr.Zero)
{
throw new Win32Exception(num1,
SR.GetString("ErrorCreatingHandle"));
}
this.ownHandle = true;
HandleCollector.Add(ptr2,
NativeMethods.CommonHandles.Window);
}
}
}
}
As you can see that there are 2 points where "Error creating window handle"
exception will throw. One is OutOfMemoryException and another is
Win32Exception. Can you confirm if your exception is OutOfMemoryException
or Win32Exception.

Normally the OutOfMemoryException is caused by too many user objects are
created in the process which may hit the process limitation. You may try to
remove some controls from the designer to see if this will eliminate the
exception.

While for Win32Exception, it is caused by CreateWindowEx win32 API calling
failed. You may check Win32Exception.NativeErrorCode property to see what
exact error CreateWindowEx win32 API is meeting.

Additionally, I have tried to perform some research in our internal
database, but all the "Error creating window handle" errors I found do not
have the code path from TextBoxDesigner.get_PasswordChar. They are all
runtime exceptions. It seems that Microsoft did not recieve your exact
problem before.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hey Jeff,

Thanks again for your reply. I'm on a roll with finding new things, it
seems like ("ConfigurationErrorException when reading protected config..." is
another one). I can't scientifically prove that the exception I'm receiving
would be the Win32 exception, but I'd be very surprised if it was an memory
exception. My user control has less than 20 controls on it, and I have 2
gigs of ram in my machine - so memory shouldn't be a problem.

But like I said, I haven't been able to reproduce this on any other form -
only the one. Perhaps I'll simply try and delete the text box and re-add it.
I'll post back and let you know how that goes.

Cheers - and thanks for all the help!

- ryan.

"Jeffrey Tan[MSFT]" said:
Hi Ryan,

Yes, I understand your concern.

It seems that this exception is generated in NativeWindow.CreateHandle
method, while NativeWindow class is trying to create the TextBox control.
Below is the source code of NativeWindow.CreateHandle method:

public virtual void CreateHandle(CreateParams cp)
{
IntSecurity.CreateAnyWindow.Demand();
if (((cp.Style & 0x40000000) != 0x40000000) || (cp.Parent ==
IntPtr.Zero))
{
IntSecurity.TopLevelWindow.Demand();
}
lock (this)
{
this.CheckReleased();
NativeWindow.WindowClass class1 =
NativeWindow.WindowClass.Create(cp.ClassName, cp.ClassStyle);
lock (NativeWindow.createWindowSyncObject)
{
if (this.handle == IntPtr.Zero)
{
class1.targetWindow = this;
IntPtr ptr1 =
UnsafeNativeMethods.GetModuleHandle(null);
IntPtr ptr2 = IntPtr.Zero;
int num1 = 0;
try
{
if ((cp.Caption != null) &&
(cp.Caption.Length > 0x7fff))
{
cp.Caption = cp.Caption.Substring(0,
0x7fff);
}
ptr2 =
UnsafeNativeMethods.CreateWindowEx(cp.ExStyle, class1.windowClassName,
cp.Caption, cp.Style, cp.X, cp.Y, cp.Width, cp.Height, new HandleRef(cp,
cp.Parent), NativeMethods.NullHandleRef, new HandleRef(null, ptr1),
cp.Param);
num1 = Marshal.GetLastWin32Error();
}
catch (NullReferenceException exception1)
{
throw new
OutOfMemoryException(SR.GetString("ErrorCreatingHandle"), exception1);
}
class1.targetWindow = null;
if (ptr2 == IntPtr.Zero)
{
throw new Win32Exception(num1,
SR.GetString("ErrorCreatingHandle"));
}
this.ownHandle = true;
HandleCollector.Add(ptr2,
NativeMethods.CommonHandles.Window);
}
}
}
}
As you can see that there are 2 points where "Error creating window handle"
exception will throw. One is OutOfMemoryException and another is
Win32Exception. Can you confirm if your exception is OutOfMemoryException
or Win32Exception.

Normally the OutOfMemoryException is caused by too many user objects are
created in the process which may hit the process limitation. You may try to
remove some controls from the designer to see if this will eliminate the
exception.

While for Win32Exception, it is caused by CreateWindowEx win32 API calling
failed. You may check Win32Exception.NativeErrorCode property to see what
exact error CreateWindowEx win32 API is meeting.

Additionally, I have tried to perform some research in our internal
database, but all the "Error creating window handle" errors I found do not
have the code path from TextBoxDesigner.get_PasswordChar. They are all
runtime exceptions. It seems that Microsoft did not recieve your exact
problem before.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Ryan,

Oh, it seems that your another ConfigurationErrorException issue is still
working with my colleague Steven Cheng. I have just discussed with him with
this issue, and he is still researching and discussing this issue with US
developer team. I am sure he will give you a follow up in that thread ASAP.

Regarding our issue, yes, I agree that the simplest way may be delete and
re-add the TextBox and have a try, I hope this will resolve the problem.
Anyway, please feel free to feedback result here.

If you are curious, we have several ways to troubleshoot the issue by
debugging the VS2005 IDE:

1. You may use windbg to attach the VS2005 IDE project, and set a
breakpoint on user32!CreateWindowExW and user32!CreateWindowExA, then you
may break in NativeWindow.CreateHandle method while calling
UnsafeNativeMethods.CreateWindowEx(). Then you may check the return value
and Last win32 error of CreateWindowEx. Note: since CreateWindowEx is a
frequently called API, windbg may break in various other places which are
not we want to break.

2. You may use another instance of VS2005 IDE to debug your problematic
VS2005 IDE project, in the debug "Exceptions..." dialog, you may open the
"first chance" exception break for Win32Exception and OutOfMemoryException.
Then, whenever one of these 2 exceptions are thrown, the VS2005 debugger
will break, and you can find out which exception generated this "Error
creating window handle" error message.

Note: by using debuggers, you'd better set the correct symbol path for it,
then the debugger will have the correct symbol information for all FCL
assemblies.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Ryan,

Have you reivewed my last reply? Does it make sense to you? If you still
need any help or have any concern, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

cranley

Hello Jeff,

Sorry for the late reply - I've read it and understand it, however I
haven't yet tried your proposed method of debugging. I tried deleting
and readding the textbox, but it did not work. Also, I received the
same error on a different user control I was creating (not entirely
sure why). I decided to give up on the PasswordChars and simply
utilize the UseDefaultPasswordChars property (or whatever it's called)
for 3 reasons:

1. It works no matter what
2. It's standard in windows, and
3. I didn't know about it in the first place.

Thanks.

- ryan.
 
J

Jeffrey Tan[MSFT]

Hi Ryan,

Yes, VS IDE issues and design-time issues are hard to troubleshoot without
intensive debugging of the VS IDE, however, finding the root cause is not
always that simple.

Anyway, I am glad to see that you have found a suitable workaround for your
issue. If you need further help, please feel free to post. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top