Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format.

102 views
Skip to first unread message

Tim Reynolds

unread,
Mar 10, 2004, 4:11:10 PM3/10/04
to
Team,

I have made this same post in .dotnet.languages.c#, but since it pertains to EIF & Logging Block, I decided to post here to the logging experts. Please advise. Thank you:

I am receiving this exception:


A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: Input string was not in a correct format.

on this line of code:

VOSEWebServicesIncomingEventSource.Raise(messageEvent);

where messageEvent is of type : Microsoft.ApplicationBlocks.Logging.Schema.AuditMessageEvent (from MS Logging Block)
and was built with this code in preceding method (auditMessageEvent = messageEvent):

public static void PublishAuditEvent(string message, LogLevel logLevel, EventLogEntryType eventLogEntryType, CustomEventSource customEventSource)
AuditMessageEvent auditMessageEvent = new AuditMessageEvent();
auditMessageEvent.Message = message;
auditMessageEvent.EventPublishLogLevel = (int)logLevel;
auditMessageEvent.EventLogEntryTypeID = (int)eventLogEntryType;

and VOSEWebServicesIncomingEventSource is defined as:

private static EventSource VOSEWebServicesIncomingEventSource = new EventSource("VOSE Web Services Incoming");

EventSource being of type Microsoft.EnterpriseInstrumentation.EventSource

I have nothing else besides the exception to go from - I have no clue which string is really bad.

Please advise,

Thanks,
Tim Reynolds
Verizon FL



Mike Hayton [MS]

unread,
Mar 10, 2004, 6:02:58 PM3/10/04
to
Hi Tim,

I see that its a first chance exception, does this mean that the exception
is being handled by the code?
How do you recieve this exception? (in the debugger with frist chance
exceptions turned on?)

Can you wrap the line of code with a

try
{
VOSEWebServicesIncomingEventSource.Raise(messageEvent);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

and send us the output? There may be no exception surfaced if it is handled
(caught) by the code somewhere within the Raise().
By default the Raise() will not throw - any internal exceptions are
ignored, but can be set to be output to the EventLog, or be thrown back up
to the code calling Raise().

FYI: Typically this System.FormatException happens in due to a call to
Enum.Parse(string) where you try to convert a string into its corresponding
enum type.

Cheers

Mike


--------------------
| Team,

VOSEWebServicesIncomingEventSource.Raise(messageEvent);

Please advise,

|

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Tim Reynolds

unread,
Mar 11, 2004, 9:36:14 AM3/11/04
to
Mike,
Thanks for your reply. Yes I am in the debugger. You ask if first chance was turned on. I don't see an option for first chance per say, but I have selected the option to break into the debugger for the 4 exception types noted on the Exceptions form (C++ Exceptions, Common Language Runtime Exceptions, Native Run-Time Checks, and Win32 Exceptions).

Can you please explain to me what first time exceptions are?

Also, I ran with the piece of code you provided. However, the catch block did not catch the exception...???? The code execution went from the raise to the break - skipping the catch block. This I don't understand - if this is an exception - why isn't it being caught -??? -

However, I did use the Locals window to find the value in exception - Here is what it shows (sorry about the formatting):
- $exception {System.FormatException} System.FormatException
- System.SystemException {"Input string was not in a correct format."} System.SystemException
- System.Exception {"Input string was not in a correct format." } System.Exception
System.Object {System.FormatException} System.Object
_className null string
_COMPlusExceptionCode -532459699 int
_exceptionMethod <undefined value> System.Reflection.MethodBase
_exceptionMethodString null string
_helpURL null string
_HResult -2146233033 int
_innerException { } System.Exception
_message "Input string was not in a correct format." string
_remoteStackIndex 0 int
_remoteStackTraceString null string
_source null string
_stackTrace <undefined value> System.Object
_stackTraceString null string
_xcode -532459699 int
_xptrs 0 int
HelpLink null string
HResult -2146233033 int
InnerException { } System.Exception
Message "Input string was not in a correct format." string
Source null string
StackTrace null string
TargetSite <undefined value> System.Reflection.MethodBase


What is also interesting is that the line is highlighted green. Other real exceptions being thrown by my app are highlighting yellow. Why is it green. The line is the .raise method call in this code:

try
{
VOSEWebServicesIncomingEventSource.Raise(messageEvent);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

break;

Thanks again,

Tim Reynolds
Verizon FL


btw - 2 other exceptions I am receiving when starting my web services app in debug mode with breaks at every exception are:

A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path "VOSE.WebServices.PDB" is denied. (I verified the file is there and is not readonly) - I get 5 of these


A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Error binding to target method. - I get 15 to 20 of these.

Any ideas on these - or shall I open new posting?

Mike Hayton [MS]

unread,
Mar 11, 2004, 2:05:49 PM3/11/04
to
From VS under the Debug -> Exceptions option, the Exceptions dialog
appears.
The layout of this dialog has changed from VS version to version, but it
allows you set the debugger to halt:
1 - when an exception is thrown (this is regardless of whether the
exception is caught and handled by code further up the call stack).
2 - when an exception is thrown but unhandled (i.e. not caught) by any of
the code on the call stack.

A "First chance exception" is option 1 above. Option 2 brings up a dialog
saying something like the "The following exception was unhandled".

From the test you performed (wrapping the Raise() method with a
try...catch) you can see that somewhere within the Raise() (or the methods
Raise calls..) and exception is being thrown (due to the first chance
exception that you get) however the exception is caught and handled by code
before the Raise() method returns. (i.e. your catch code never gets any
execution).

Now exceptions are more costly to throw and for perf reasons it would be
better if this exception was not throwing. The general rule of exceptions
is only throw them in exceptional situations. In some regards you can argue
that Enum.Parse() throwing is a bad design as its quite possible that the
string input is not valid.

Having said all that.
- When the debugger breaks on the exception and you look at the local
variable $exception what is its value of the Stack property?
- Drill into the inner exceptions and what does their Stack property say?
- What does the call stack show when the debugger breaks?
- Can you try removing the logEventSink from the EI.config and seeing if
the first chance exception still occurs? I know there is an Enum.Parse() in
the log event sink. If this doesnt stop the first chance exception can you
remove the other event sinks one by one.
- Can you send me your EI.config file (before the changes of above)?

I can see any green/yellow in the text only posting that I have - I think
the green/yellow you are talking about may be color coding that the
debugger uses to help show what values have changed and what ones have
stayed the same between breakpoints.

Cheers

Mike

--------------------
One more thing - I tested out the sample that came with the Logging Block -
called BasicSQLSinkSample, and the same exception occured on the Raise call
of EventSource.Application.

A first chance exception of type 'System.FormatException' occurred in
mscorlib.dll

Additional information: Input string was not in a correct format.

Yes I was in debug mode with breaks at all exception types.

Thanks,
Tim

TomD...@captaris.com

unread,
Dec 22, 2004, 4:23:15 PM12/22/04
to

I suspect that this problem is due to how
Microsoft.ApplicationBlocks.Logging.Schema.CommonEvent.SetApplicationLevel()
works.

This method first tries to convert the applicationLogLevel to an int
using int.Parse. If a FormatException is thrown/caught, it then checks
the applicationLogLevel against an enum using string compares.

The applicationLogLevel is what's stored in the application's
exe.config file under

<configuration>
<appSettings>
<add key="applicationLogLevel" value="debug"/>
<add key="instrumentationConfigFile"
value="EnterpriseInstrumentation.config"/>
</appSettings>
</configuration>

The Fix:

If you use the int values for the applicationLogLevel that correlate to
the enum, the exception won't be thrown. The enum is:

public enum LogLevel
{
// Fields
Always = 1,
Debug = 5,
Error = 2,
Informational = 4,
None = 0,
Warning = 3
}


So, the example application.exe.config file above would look like:

<configuration>
<appSettings>
<add key="applicationLogLevel" value="5"/>
<add key="instrumentationConfigFile"
value="EnterpriseInstrumentation.config"/>
</appSettings>
</configuration>

-Tom

0 new messages