Solved

Input String was not in the correct format - Strange places

Posted on 2007-11-29
8
453 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
 
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
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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now