jitDebugging

J

Jeff Gaines

I am trying to enable jitDebugging in the machine.config file.

I have amended it to read:

<configuration>
<system.windows.forms jitDebugging="true" />
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />

etc..

Now when I load a project I get an error in the IDE:

Unrecognized configuration section system.windows.forms.
(C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line
13)

I thought I had followed the instructions but apparently not. Can anybody
tell me what line I need to add and where to put it please?
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

Setting jitDebugging in the machine.config file means turning on the
Winform JIT debugging feature for the entire machine. Is this what you
wanted to achieve?

If you only wanted to enable JIT debugging for certain Winform project, you
may just add jitDebugging attribute to app.config. Steps are listed below:
1. In Solution Explorer, right click the project item. Select Add-> New
Items....
2. In the dialog, find "Application Configuration File" and click "Add"
3. Input the following content in the app.config:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

I have also tried to add <system.windows.forms jitDebugging="true" /> to
the machine.config in the path:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config. But I did not get any
error in VS2005 IDE.

Can you provide detailed steps to help me reproduce the problem? 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

Jeff Gaines

Hi Jeff,

Setting jitDebugging in the machine.config file means turning on the
Winform JIT debugging feature for the entire machine. Is this what you
wanted to achieve?

I do, I am not sure if the problem is in my code or in a bought in
component so I thought this would be the best way :)
I have also tried to add <system.windows.forms jitDebugging="true" /> to
the machine.config in the path:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config. But I did not get any
error in VS2005 IDE.

Can you provide detailed steps to help me reproduce the problem? Thanks.

I opened machine.config in a text editor (Ultraedit) and altered it to read:

<configuration>
<system.windows.forms jitDebugging="true" />
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />

[file continues]

When double clicking a solution file and trying to look at a form I get
the following error in the IDE:

Unrecognized configuration section system.windows.forms.
(C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config line
13)
Hide

at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean
ignoreLocal)
at
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors
schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String
configKey)

Line 13 is the line I added. It doesn't look anything like the other lines
though which are more complex. Everything works fine if I take that line
out.

XML/HTML is a bit of a mystery to me so I wondered if I am doing something
wrong that would be obvious to somebody who understands it better?
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

Thank you for the feedback.

This also looks like a strange error for me, since I copied the config
snippet you provided and pasted it into my machine.config file. However, I
did not get any error after opening a test Winform C# project.

I would suspect that if there is any invisible characters in your
machine.config(such as formatting characters from Word), which may appear
invalid to the parser. Can you copy the config snippet into the notepad and
re-copy it back into the machine.config for testing purpose? Since notepad
will eliminate any formatting characters, this will ensure the text we
pasted into the machine.config is clean.

Actually, I have done some further testing regarding this issue. I just
malformed the machine.config on purpose by adding a garbage "test" word in
the file:
<configuration>
<system.windows.forms jitDebugging="true" />test
<configSections>
<section name="appSettings"
type="System.Configuration.AppSettingsSection, System.Configuration,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
restartOnExternalChanges="false" requirePermission="false" />

I opened the testing winform project but did not get any error like you
got. By creating an Asp.net project, I will get the error you are providing
in the error panel. But I still did not get any stack. So I would like to
confirm that if you got this error in an Asp.net project or Winform
project? Do you get this error if you create an empty new Winform project?
This will help us to find out if this error is your project specific.

Additionally, it seems that the call stack you provided is not complete, it
does not tell us which code part is trying to parse the machine.config
file. I am not sure, but is it possible you get the full call stack
regarding it for analysis? I would also recommend you to provide a screen
shot regarding this error, so that I can understand which part in the IDE
you get this error. Thanks.

Finally, in order to isolate this problem, can you trying your steps on a
new machine? This will help us to identify if it is your machine specific.

I would look forward for your further testing result. 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.
==================================================
 
J

Jeff Gaines

Hi Jeff,

Thank you for the feedback.

This also looks like a strange error for me, since I copied the config
snippet you provided and pasted it into my machine.config file. However, I
did not get any error after opening a test Winform C# project.

I would suspect that if there is any invisible characters in your
machine.config(such as formatting characters from Word), which may appear
invalid to the parser. Can you copy the config snippet into the notepad and
re-copy it back into the machine.config for testing purpose? Since notepad
will eliminate any formatting characters, this will ensure the text we
pasted into the machine.config is clean.

OK, I copied it in from your post and also typed it in manually but I get
the same problem.
I opened the testing winform project but did not get any error like you
got. By creating an Asp.net project, I will get the error you are providing
in the error panel. But I still did not get any stack. So I would like to
confirm that if you got this error in an Asp.net project or Winform
project? Do you get this error if you create an empty new Winform project?
This will help us to find out if this error is your project specific.

This is a Winform Project.

I created a new simple Winform Project and it built and ran fine with the
jitDebugging string in the machine.config file. I then closed it and
re-opened it and the error appeared. I also opened several other projects
and the error appears immediately on opening them if they open with a
Windows Form in the designer. The error does not appear if it is a class
file that opens first but then as soon as I open a form in the project the
error is back. In fact most apps build and run but I can't edit Forms in
the designer.
Finally, in order to isolate this problem, can you trying your steps on a
new machine? This will help us to identify if it is your machine specific.

My 'clean' machine has Vista on it so it may not be a good idea to put VS
2005 on that.

As an experiment I altered the app.config file for a project and put the
jitDebugging string in that. That caused some real problems, since on
running it couldn't find any of the app configuration strings.

I think that sensibly I should do a clean re-install on the development
PC, put VS 2005 on first and try the jitDebugging string again. I will
then install the bought in component I am using and see the effect. I did
try several file manager components before settling on the one I bought, I
may need to ask the supplier if there is anything in their code that might
cause this issue. There will probably be remnants of the others I tested
in the Registry and it is difficult to know what the combined effect might
be.

Many thanks for your input. The support from you and your colleagues in
these groups is a valuable part of my MSDN subscription, I'll remember
that when I get my renewal invoice in November :)
 
J

Jeff Gaines

On 19/08/2007 in message <[email protected]> Jeff
Gaines wrote:

Sorry to follow up my own post but I have now carried out a clean install
of XP Pro (MSDN retail) SP2 on the box that had Vista on it. I then
installed VS2005 and SP1 for VS2005.

I started a small test app and made sure it ran OK then altered
machine.config to read:

<configuration>
<system.windows.forms jitDebugging="true" />
<configSections>
<section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
etc.

I also added App.config to the project which reads:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

The good news is the app continues to build and run and the IDE does not
complain about the configuration. But JITDebugging does not appear to
work. I introduced a divide by zero error in the app which is triggered on
a button press. I ran the app directly from its .exe file outside the IDE
and when it hits the error a dialog appears offering Details, Continue or
Quit. Clicking details produces a listing of the problem with instructions
for configuring JITdebugging.

Am I correct in believing that I should get an opportunity to run the
de-bugger? If so I seem to have a real issue here.

I have checked the registry and all the keys are there with appropriate
values and correct paths.

What a pity the IDE doesn't have an option to just turn on machine wide
JITDebugging!

The machine has been re-booted several times so VS2005 should be reading
the updated machine.config.
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

Thank you for the kindly feedback.

Yes, I can reproduce out this problem. I have tried to add the
jitDebugging=true in app.config for a sample Winform project. However, the
..Net Winform default error dialog still shows without enabling JIT
debugging.

I have test this on more than 3 machines, only one Vista machine pops up
the JIT debugging dialog. The XP and Win2003 testing machines both have the
same problem as you(JIT debugging not working).

I have tried to use Process Monitor from sysinternals to log the
[appname].exe.config file access records. I find that CLR really probes the
[appname].exe.config file during process startup. However, for unknown
reason, the jitDebugging=true setting did not work as expected.

Anyway, I will perform some further research to find out the root cause. I
will get back to you ASAP. Thanks for your patient.

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 Jeff,

Sorry for letting you wait.

I have performed intensive debugging over this issue. Finally, I found the
root cause.

It seems that we should not place the <system.windows.forms
jitDebugging="true" /> section in the begin of the machine.config. This
will break the .Net Winform JIT debugging feature..Net will always probe
the machine.config <system.windows.forms> section before app.config. If we
remove this section from machine.config, app.config <system.windows.forms
jitDebugging="true" /> will ok without any problem. You may give it a try.

Also, to use <system.windows.forms jitDebugging="true" /> in the
machine.config at the machine-wide. You have to place the
<system.windows.forms jitDebugging="true" /> at the end closing of
<configuration>, just before </configuration>, like this:
....
</system.web>
<system.windows.forms jitDebugging="true"/>
</configuration>

Based on my testing, this works well on my machine.

If you are curious about the internal debugging result, below is some
information.

If .Net winform can probe jitDebugging="true" in app.config, it will setup
a "DebuggableCallback" for the window procedure, if not, it will use
"Callback". "Callback" method will set a big try...catch to catch any
exception in the Winform app and display an error dialog, see the code
below(OnThreadException in the code will show the error dialog):
private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
{
Message m = Message.Create(hWnd, msg, wparam, lparam);
try
{
if (this.weakThisPtr.IsAllocated && (this.weakThisPtr.Target !=
null))
{
this.WndProc(ref m);
}
else
{
this.DefWndProc(ref m);
}
}
catch (Exception exception)
{
this.OnThreadException(exception);
}
finally
{
if (msg == 130)
{
this.ReleaseHandle(false);
}
if (msg == NativeMethods.WM_UIUNSUBCLASS)
{
this.ReleaseHandle(true);
}
}
return m.Result;
}

While "DebuggableCallback" will not catch the dialog but let the exception
throw out for JIT debugging:

private IntPtr DebuggableCallback(IntPtr hWnd, int msg, IntPtr wparam,
IntPtr lparam)
{
Message m = Message.Create(hWnd, msg, wparam, lparam);
try
{
if (this.weakThisPtr.IsAllocated && (this.weakThisPtr.Target !=
null))
{
this.WndProc(ref m);
}
else
{
this.DefWndProc(ref m);
}
}
finally
{
if (msg == 130)
{
this.ReleaseHandle(false);
}
if (msg == NativeMethods.WM_UIUNSUBCLASS)
{
this.ReleaseHandle(true);
}
}
return m.Result;
}

To use "DebuggableCallback" or "Callback" is determined in the following
method by checking WndProcShouldBeDebuggable property:

internal void AssignHandle(IntPtr handle, bool assignUniqueID)
{
lock (this)
{
this.CheckReleased();
this.handle = handle;
if (userDefWindowProc == IntPtr.Zero)
{
string lpProcName = (Marshal.SystemDefaultCharSize == 1) ?
"DefWindowProcA" : "DefWindowProcW";
userDefWindowProc = UnsafeNativeMethods.GetProcAddress(new
HandleRef(null, UnsafeNativeMethods.GetModuleHandle("user32.dll")),
lpProcName);
if (userDefWindowProc == IntPtr.Zero)
{
throw new Win32Exception();
}
}
this.defWindowProc = UnsafeNativeMethods.GetWindowLong(new
HandleRef(this, handle), -4);
if (WndProcShouldBeDebuggable)
{
this.windowProc = new
NativeMethods.WndProc(this.DebuggableCallback);
}
else
{
this.windowProc = new NativeMethods.WndProc(this.Callback);
}
....................

While this "WndProcShouldBeDebuggable " property checking logic is
implemented in the "WndProcFlags" static property:

internal static bool WndProcShouldBeDebuggable
{
get
{
return ((WndProcFlags & 4) != 0);
}
}

private static int WndProcFlags
{
get
{
int wndProcFlags = NativeWindow.wndProcFlags;
if (wndProcFlags == 0)
{
if (userSetProcFlags != 0)
{
wndProcFlags = userSetProcFlags;
}
else if (userSetProcFlagsForApp != 0)
{
wndProcFlags = userSetProcFlagsForApp;
}
else if (!Application.CustomThreadExceptionHandlerAttached)
{
if (Debugger.IsAttached)
{
wndProcFlags |= 4;
}
else
{
wndProcFlags =
AdjustWndProcFlagsFromRegistry(wndProcFlags);
if ((wndProcFlags & 2) != 0)
{
wndProcFlags =
AdjustWndProcFlagsFromMetadata(wndProcFlags);
if ((wndProcFlags & 0x10) != 0)
{
if ((wndProcFlags & 8) != 0)
{
wndProcFlags =
AdjustWndProcFlagsFromConfig(wndProcFlags);
}
else
{
wndProcFlags |= 4;
}
}
}
}
}
wndProcFlags |= 1;
NativeWindow.wndProcFlags = (byte) wndProcFlags;
}
return wndProcFlags;
}
}

So, finally, it is "AdjustWndProcFlagsFromConfig" method that probes
"machine.config" and "app.config":
[MethodImpl(MethodImplOptions.NoInlining)]
private static int AdjustWndProcFlagsFromConfig(int wndProcFlags)
{
if (WindowsFormsSection.GetSection().JitDebugging)
{
wndProcFlags |= 4;
}
return wndProcFlags;
}

This is my findings. But I still did not find out why .Net will not allow
the <system.windows.forms jitDebugging="true" /> section to reside at the
begin of the machine.config. Anyway, I think we have a resolution for the
problem now.

Hope it 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

Jeff Gaines

Hi Jeff,

Sorry for letting you wait.

Goodness me, that wasn't a wait :)
I have performed intensive debugging over this issue. Finally, I found the
root cause.

Well done!
This is my findings. But I still did not find out why .Net will not allow
the <system.windows.forms jitDebugging="true" /> section to reside at the
begin of the machine.config. Anyway, I think we have a resolution for the
problem now.

Hope it helps.

It most certainly does and it now works here as well!

Thank you for all the effort you have put into this, it is very much
appreciated.

I wonder why it hasn't been noticed by other programmers in the community.
Although I sometimes think it is a miracle that computers, and complex
software, work at all rather than sometimes they don't.

Many thanks again :)
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

Glad to see my reply can help you.

Yes, I am also surprised to see that no people mentioned this behavior yet.
I think this is because few people tries to enable the Winform jitdebugging
on machine wide, they normally enable it in app.config.

Anyway, 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.
 
J

Jeffrey Tan[MSFT]

Hi Jeff,

I am not sure if you are still curious about the root cause. I have
discussed our findings with product dev team in Microsoft. I think we have
the explanation now:

Basically, the <configSections> element contents describe the classes to
use to read and interpret subsequent various configuration sections (thus
the name). If you search in the machine.config, you will find that there is
a child section element:
<section name="system.windows.forms"
type="System.Windows.Forms.WindowsFormsSection, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

This tells .NET that the System.Windows.Forms.WindowsFormsSection class
should be used to read the contents of the "system.windows.forms" element.
Only after processesing this element does the system know what type to use
to read the configuration\system.windows.form element.

So our configuration\system.windows.form element must follow the closing of
the configSections element. We can place this element anywhere in
machine.config as a direct child of the configuration element as long as it
follows the close of the configSections element, not necessarily just at
the end of machine.config.

This explains why setting the <system.windows.forms jitDebugging="true" />
before <configSections> will fail mysteriously.

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

Jeff Gaines

So our configuration\system.windows.form element must follow the closing of
the configSections element. We can place this element anywhere in
machine.config as a direct child of the configuration element as long as it
follows the close of the configSections element, not necessarily just at
the end of machine.config.

This explains why setting the <system.windows.forms jitDebugging="true" />
before <configSections> will fail mysteriously.

Hope this helps.

Yes indeed, thanks Jeffrey, carefully saved :)
 

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