Solved

Input String was not in the correct format - Strange places

Posted on 2007-11-29
8
454 Views
Last Modified: 2013-11-07
I am getting a very very odd error.  I have a web application that was painstakingly converted from C# to VB .NET.  Now I know there is a lot of work involved to getting this to function, but I'm seeing some strange errors.  I have a function that is giving me the "Input string was not in hte correct format" error, however, it does it on odd lines.  In the Attached snippet, the error is on the last "End If" line.  If I comment the whole block out and try to manually return an integer, it will throw the error on one of my commented lines.  The code is below (not sure how the snippet system works yet).  Also, this is .NET Framework 2.0.  Compiles with no errors or warnings.

            Dim result As Integer = 0

            Dim key As String = "GetTotalCalls_" & commId & "_" & sDate.ToShortDateString() & "_" & eDate.ToShortDateString()
            If BaseCallLog.Settings.EnableCaching AndAlso BizObject.Cache(key) IsNot Nothing Then
                result = CInt(BizObject.Cache(key))
            Else
                If commId = 0 Then
                    Dim cList As List(Of Community.Community) = Community.Community.GetCommunitiesByUser(Membership.GetUser().UserName)
                    If cList.Count > 0 Then
                        For Each comm As Community.Community In cList
                            result += CInt(SiteProvider.CallLog.GetCallVolume(sDate, eDate, comm.TableName))
                        Next
                    End If
                Else
                    Dim tableName As String = Community.Community.GetTableNameFromCommunityId(commId)
                    result += CInt(SiteProvider.CallLog.GetCallVolume(sDate, eDate, tableName))
                End If
                BaseCallLog.CacheData(key, result)
            End If
            Return result
Dim result As Integer = 0
 
            Dim key As String = "GetTotalCalls_" & commId & "_" & sDate.ToShortDateString() & "_" & eDate.ToShortDateString()
            If BaseCallLog.Settings.EnableCaching AndAlso BizObject.Cache(key) IsNot Nothing Then
                result = CInt(BizObject.Cache(key))
            Else
                If commId = 0 Then
                    Dim cList As List(Of Community.Community) = Community.Community.GetCommunitiesByUser(Membership.GetUser().UserName)
                    If cList.Count > 0 Then
                        For Each comm As Community.Community In cList
                            result += CInt(SiteProvider.CallLog.GetCallVolume(sDate, eDate, comm.TableName))
                        Next
                    End If
                Else
                    Dim tableName As String = Community.Community.GetTableNameFromCommunityId(commId)
                    result += CInt(SiteProvider.CallLog.GetCallVolume(sDate, eDate, tableName))
                End If
                BaseCallLog.CacheData(key, result)
            End If
            Return result

Open in new window

0
Comment
Question by:traxion
  • 4
  • 3
8 Comments
 
LVL 9

Author Comment

by:traxion
ID: 20374557
Here's hte Stack Trace:

[FormatException: Input string was not in a correct format.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +211
   Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +74

[InvalidCastException: Conversion from string "GetTotalCalls_" to type 'Double' is not valid.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value, NumberFormatInfo NumberFormat) +218
   Microsoft.VisualBasic.CompilerServices.Conversions.ToDouble(String Value) +6
   SEM5.SEM5.BLL.CallLog.CallLog.GetTotalCalls(Int32 commId, DateTime sDate, DateTime eDate) in D:\DEV\ArialObjects\ObjectsBinary\SEM5\BLL\CallLog\CallLog.vb:249
   SEM.Members_Client_Default.UpdateStatLabels() in D:\DEV\Arial VB Final\AVB\Members\Client\Default.aspx.vb:69
   SEM.Members_Client_Default.Page_Load(Object sender, EventArgs e) in D:\DEV\Arial VB Final\AVB\Members\Client\Default.aspx.vb:48
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

 
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20374627
>>If I comment the whole block out and try to manually return an integer, it will throw the error on one of my commented lines.

This indicates that your latest code isnt deployed on the web server you are trying to debug. Try commenting your code and then deploying it again afresh and see if this happens again
0
 
LVL 3

Expert Comment

by:bnaveke
ID: 20374693
Check the value of commId.  If it is Null or Empty it may through this error. Then check this condition on other variables including any that are getting passed in.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 9

Author Comment

by:traxion
ID: 20374715
Ok...the web server is local on my machine...I have code in two assemblies, both in hte same solution, but recompiled and deployed.  This is a "Web application".

Also, just for the heck of it, I changed the function definition and made all values it accepts "Optionals" with a default value.  I then commented everything and added the line "Return 5" to return an integer value of 5.  My commented lines were then throwing the error.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20374745
Can you debug line by line to check if the debug actually executes the commented lines? I am just trying to make sure that it isnt the old uncommented code that is being execute because of some strange reason
0
 
LVL 9

Author Comment

by:traxion
ID: 20375075
Well...I may have solved the issue.  I had two projects in hte same solution.  Both projects had hte same namespace but also the same assembly name and were stepping on eachother.  Now that I have the projects debugged, I merged the files into a single project and updated my references.  This is the way the application was originally, but there were two many errors to debug after the translation so I separatd the Bus. Logic and Data Access layers into a separate assembly.  Once I changed the assembly name of the layered project, it fixed the problem...so I have merged into a single assembly now and am dealing with a different error.  Thanks for everyone's help.  I'd still like ot assign points, so I'll show you my resulting error:


Private Sub New()
Line 9:  		End Sub
Line 10:         Public Shared ReadOnly Settings As SEMSection = DirectCast(WebConfigurationManager.GetSection("SEMv5"), SEMSection)
Line 11: 	End Class
Line 12: End Namespace
 
 
Source File: D:\DEV\Arial VB Final\AVB\nTierObjects\Globals.vb    Line: 10 
 
Stack Trace: 
 
 
[InvalidCastException: Unable to cast object of type 'SEM5.SEM5.SEMSection' to type 'SEM5.SEM5.SEMSection'.]
   SEM5.SEM5.Globals..cctor() in D:\DEV\Arial VB Final\AVB\nTierObjects\Globals.vb:10
 
[TypeInitializationException: The type initializer for 'SEM5.SEM5.Globals' threw an exception.]
   SEM5.SEM5.BLL.Community.BaseCommunity.get_Settings() in D:\DEV\Arial VB Final\AVB\nTierObjects\BLL\Community\BaseCommunity.vb:12
 

Open in new window

0
 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20375759
>>'SEM5.SEM5.SEMSection' to type 'SEM5.SEM5.SEMSection'. clearly indicates that you might be using two different assemblies for SEMSection and when the SEMSection object made using one assemblty is type casted using SEMSection from another namespace it creates the problem
0
 
LVL 9

Author Comment

by:traxion
ID: 20376068
surajquptha - you nailed it. ;)  I actually had figured it out just before reading your post.  I was still referencing the old assembly.  Cleaned up the folders, fixed the assembly name, and away we go.  The application is now functional.  Thanks!  Full points awarded.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question