S
Smithers
I solved this, but would appreciate an explanation if one is to be
had...this seems like a real WTF to me (sorry, I'm particularly put out
right now).
Please note 2 questions following the explanation of the issue:
This humble line of code choked:
System.Data.SqlClient.SqlConnection c = new
System.Data.SqlClient.SqlConnection();
Unbelieveable - eh? It's in a normal, "goin' down the road" Windows Forms
class - nothing fancy.
Here's the exception, followed by 4 levels of inner exceptions:
System.TypeInitializationException : The type initializer for
'System.Data.SqlClient.SqlConnection' threw an exception."
Inner exception:
"The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw
an exception.
Next inner exception:
"The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters'
threw an exception."
Next inner exception:
"Configuration system failed to initialize"
Next inner exception:
"Unrecognized configuration section MyCustomConfigurationSectionNameHere"
SOLUTION:
At the end of the day, I solved this be deleting the custom configuration
section in App.config (I hadn't yet created an entry for it in
<configSections> where all custom configuration sections are supposed to
have an entry. I suspect I could have created that entry as another solution
to this problem).
QUESTION #1:
How and why does the SqlClient's connection object care about App.config...
much less CHOKE when a custom configuration section is in App.config that
isn't completely defined? FWIW I'm NOT using App.config to store
connectionStrings - so the SqlClient has no business, AFAIKT, caring that
much about App.config. Plus I'm doing all kinds of things elsewhere with
App.config and custom configuration sections and SectionHandlers - and none
of those things choked.
QUESTION #2:
WHY does the problem NOT occur when stepping through the code? That is the
case: the problem does NOT surface when stepping through the code. It only
happens if we let the code execute without stepping through. For the heck of
it I event put the thread to sleep for a sec and let it rip (no break
points) and it choked. But put in a break point and step through and the
exception does NOT happen.
I'm the last person to claim to have found a bug - thus I'm asking for a
rational explanation for this one - if one is to be had.
FWIW: I'm using VS2008 Beta2.... also duplicated exact same behavior in
VS2005/SP2. The only difference is that VS2008 let me easily view the nested
inner exceptions all the way down to the "root cause", whereas 2005 only
gave me the first inner exception.
TO DUPLICATE:
Here is your entire App.config (could have more, but this will suffice):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<SomeSection someAttribute="yo" />
</configuration>
Put the following into a Button_Click event handling procedure in a Windows
Forms form. You'd have to substitute your ServerName or IP, database name,
UserID and password , of course:
string cs = "Data Source=SqlServerNameOrIP; Initial Catalog=DatabaseName;
Trusted_Connection=false; Password=******;User ID=BigJimSlade";
System.Data.SqlClient.SqlConnection c = new
System.Data.SqlClient.SqlConnection();
c.ConnectionString = cs;
c.Open();
if (c.State == System.Data.ConnectionState.Open)
{
MessageBox.Show("Yup");
}
else
{
MessageBox.Show("Nope");
}
Run the code with and without <SomeSection... /> in App.config - you'll see
what I'm talking about. Also try it stepping through vs not stepping through
(with App.config having the <SomeSection /> in it).
Thanks!
had...this seems like a real WTF to me (sorry, I'm particularly put out
right now).
Please note 2 questions following the explanation of the issue:
This humble line of code choked:
System.Data.SqlClient.SqlConnection c = new
System.Data.SqlClient.SqlConnection();
Unbelieveable - eh? It's in a normal, "goin' down the road" Windows Forms
class - nothing fancy.
Here's the exception, followed by 4 levels of inner exceptions:
System.TypeInitializationException : The type initializer for
'System.Data.SqlClient.SqlConnection' threw an exception."
Inner exception:
"The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw
an exception.
Next inner exception:
"The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters'
threw an exception."
Next inner exception:
"Configuration system failed to initialize"
Next inner exception:
"Unrecognized configuration section MyCustomConfigurationSectionNameHere"
SOLUTION:
At the end of the day, I solved this be deleting the custom configuration
section in App.config (I hadn't yet created an entry for it in
<configSections> where all custom configuration sections are supposed to
have an entry. I suspect I could have created that entry as another solution
to this problem).
QUESTION #1:
How and why does the SqlClient's connection object care about App.config...
much less CHOKE when a custom configuration section is in App.config that
isn't completely defined? FWIW I'm NOT using App.config to store
connectionStrings - so the SqlClient has no business, AFAIKT, caring that
much about App.config. Plus I'm doing all kinds of things elsewhere with
App.config and custom configuration sections and SectionHandlers - and none
of those things choked.
QUESTION #2:
WHY does the problem NOT occur when stepping through the code? That is the
case: the problem does NOT surface when stepping through the code. It only
happens if we let the code execute without stepping through. For the heck of
it I event put the thread to sleep for a sec and let it rip (no break
points) and it choked. But put in a break point and step through and the
exception does NOT happen.
I'm the last person to claim to have found a bug - thus I'm asking for a
rational explanation for this one - if one is to be had.
FWIW: I'm using VS2008 Beta2.... also duplicated exact same behavior in
VS2005/SP2. The only difference is that VS2008 let me easily view the nested
inner exceptions all the way down to the "root cause", whereas 2005 only
gave me the first inner exception.
TO DUPLICATE:
Here is your entire App.config (could have more, but this will suffice):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<SomeSection someAttribute="yo" />
</configuration>
Put the following into a Button_Click event handling procedure in a Windows
Forms form. You'd have to substitute your ServerName or IP, database name,
UserID and password , of course:
string cs = "Data Source=SqlServerNameOrIP; Initial Catalog=DatabaseName;
Trusted_Connection=false; Password=******;User ID=BigJimSlade";
System.Data.SqlClient.SqlConnection c = new
System.Data.SqlClient.SqlConnection();
c.ConnectionString = cs;
c.Open();
if (c.State == System.Data.ConnectionState.Open)
{
MessageBox.Show("Yup");
}
else
{
MessageBox.Show("Nope");
}
Run the code with and without <SomeSection... /> in App.config - you'll see
what I'm talking about. Also try it stepping through vs not stepping through
(with App.config having the <SomeSection /> in it).
Thanks!