The type initializer for 'MyClass' threw an exception

N

NoNickname

I developed a new ASP.NET 2.0 web service on my PC (VS2005 on windows 2000)
and tested it in a development environment on a 2003 box. And the web
service works on three different 2003 servers in a QA environment.

When I moved the application dlls over to Production onto a brand new 2003
box built special to host this web service it did not work.

I'm told that there are no differences between the QA and Production boxes
but something must be different. Has anybody seen the following error
message? Or better still do you have a resolution? I googled around but
really can’t find anything meaningful.

This is the core of the error:
Exception type: TypeInitializationException
Exception message: The type initializer for 'Global' threw an exception.


------------------
In my Global.asax file I have this line:

<%@ Application Language="C#" Inherits="Global" %>


Then Global.cs is defined as:

public partial class Global : System.Web.HttpApplication
{

public static int DebugLevel = 0;


public Global()
{ }
void Application_Start(object sender, EventArgs e)
{
string temp = null
temp = ConfigurationManager.AppSettings["DebugLevel"];
if (!string.IsNullOrEmpty(temp)) DebugLevel = int.Parse(temp);
{
}


Then in my web methods I'll have a line like this:

If(Global.DebugLevel > 5) {}

------------------
I really don’t know why this will work in QA but not in Production. My guess
is that it is some sort of permissions issue but I can't seem to find it.


Thanks.


Here is the full event log entry:


Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 9/15/2006 4:19:23 PM
Event time (UTC): 9/15/2006 8:19:23 PM
Event ID: bf87b4e625b54a588db99e30bef86643
Event sequence: 2
Event occurrence: 1
Event detail code: 0


Application information:
Application domain: /LM/W3SVC/1797328370/Root/P/v01_00-2-128028251635720044
Trust level: Full
Application Virtual Path: /P/v01_00
Application Path: D:\Inetpub\Svcs\P\v01_00\
Machine name: PSVCS01

Process information:
Process ID: 3116
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE


Exception information:
Exception type: TypeInitializationException
Exception message: The type initializer for 'Global' threw an exception.

Request information:
Request URL: http://PSVCS.com/P/v01_00/Pservice.asmx
Request path: /P/v01_00/Pservice.asmx
User host address: 10.1.112.61
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:
Thread ID: 7
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at Global..ctor()
at ASP.global_asax..ctor()
 
W

Walter Wang [MSFT]

Hi,

As Gaurav suggested, we will need detailed exception and stack trace to
know the inner most exception that caused this TypeInitializationException.
From your event log, it seems that your inherited HttpApplication class
failed to initialize.

Is it possible that your production server has installed some ISAPI
extensions?

I also suggest that you precompile your web site with debugging information
on and try to visit it locally on the production server to view the
detailed exception information.

Please reply here with the detailed exception, so that we can take further
analysis. Thank you.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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.
 
W

Walter Wang [MSFT]

Hi,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Michael D. Ober

When I have had this happen, it's usually in a line such as

myObject foo = new myObject()

and the myObject initializer is where the error is really being thrown from.
This is especially devious when you don't have a coded New() function.

Mike Ober.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top