CodeRush won't organize/cleanup the following code:
Visual BasicImports System.Xml
Imports System.Xml.Linq
Public Class Class1
Private Function ParseSyntaxData() As Dictionary(Of String, String)
' Do not get address as that should be brought in from Epicor
Dim dicResult As New Dictionary(Of String, String)
Dim strLines() As String '= Me.mmoDetailsCaseNotes.Lines
Dim intStart As Integer = 0
Dim intEnd As Integer = 0
Dim intStartSearch As Integer = 0
Dim intErrorCount As Integer = 0
Dim intCount As Integer = 0
SearchAgain:
' This will find the most recent xml
For i As Integer = intStartSearch To strLines.Length - 1
If Trim(strLines(i)).IndexOf("<ServicePro>") = 0 Then
intStart = i
ElseIf Trim(strLines(i)).IndexOf("</ServicePro>") = 0 Then
intEnd = i
intStartSearch = i + 1
Exit For
End If
If i = strLines.Length - 1 Then GoTo Finish
Next
If intStart + intEnd >= 2 Then
Dim strSyntax As String
strSyntax = "<?xml version=""1.0""?>"
For i As Integer = intStart To intEnd
strSyntax += strLines(i)
Next
XMLFIX:
Try
intCount += 1
Catch ex As XmlException
' XML quick fix
strSyntax = strSyntax.Replace(CChar("&"), "&")
strSyntax = strSyntax.Replace(CChar("'"), "'")
intErrorCount += 1
If intErrorCount <= 1 Then
GoTo XMLFIX
End If
If intErrorCount > 1 Then
ex.Data.Add("xmlTest", strSyntax)
'ex.Data.Add("Case", Me.txtCaseNumber.Text)
'ex.Data.Add("Call", Me.txtCallNumber.Text)
Dim intResult As Integer = msgAdv.Show($"{MessageStrings.DispatchSyntaxTestingError1}{intCount}. {MessageStrings.DispatchSyntaxTestingError2}", MessageBoxButtons.YesNo)
If intResult = vbYes Then GoTo SearchAgain Else GoTo Finish
End If
End Try
Try
Dim xml As System.Xml.Linq.XDocument = XDocument.Parse(strSyntax)
For Each node In xml.Elements("ServicePro").Nodes
Select Case node.NodeType
Case System.Xml.XmlNodeType.Element
dicResult(DirectCast(node, XElement).Name.ToString) = DirectCast(node, XElement).Value
End Select
Next
Catch ex As Exception
ex.Data.Add("xmlTest", strSyntax)
'ex.Data.Add("Case", Me.txtCaseNumber.Text)
'ex.Data.Add("Call", Me.txtCallNumber.Text)
Dim strMessage As String = MessageStrings.DispatchSyntaxProcessingError
msgAdv.ShowException(ex, False, strMessage)
GoTo Finish
End Try
If intStartSearch < strLines.Length Then GoTo SearchAgain
End If
Finish:
Return dicResult
End Function
End Class
The following is taken from the error log after attempting to save the vb file.
Code2020.05.21 12:28:55.4442 Error: ApplyCount for Apply variable declaration style provider exceeded on Class1.vb document
2020.05.21 12:28:55.4452 Error: Message: One or more errors occurred.
2020.05.21 12:28:55.4452 Error: Type: System.AggregateException
2020.05.21 12:28:55.4452 Error: Source: mscorlib
2020.05.21 12:28:55.4452 Error: StackTrace:
2020.05.21 12:28:55.4452 Error: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
2020.05.21 12:28:55.4452 Error: at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
2020.05.21 12:28:55.4452 Error: at System.Threading.Tasks.Task`1.get_Result()
2020.05.21 12:28:55.4452 Error: at DevExpress.CodeRush.Foundation.CodeCleanUp.CleanUpOnSaveService.ProcessDocumentSaved(ITextDocument textDocument)
2020.05.21 12:28:55.4452 Error: InnerException:
2020.05.21 12:28:55.4452 Error: Message: Exception of type 'DevExpress.CodeAnalysis.CodeCleanUp.CodeCleanUpHangedException' was thrown.
2020.05.21 12:28:55.4452 Error: Type: DevExpress.CodeAnalysis.CodeCleanUp.CodeCleanUpHangedException
2020.05.21 12:28:55.4452 Error: Source: DevExpress.CodeAnalysis
2020.05.21 12:28:55.4452 Error: StackTrace:
2020.05.21 12:28:55.4452 Error: at DevExpress.CodeAnalysis.CodeCleanUp.CodeCleanUpEngine.<Apply>d__22.MoveNext()
2020.05.21 12:28:55.4452 Error: --- End of stack trace from previous location where exception was thrown ---
2020.05.21 12:28:55.4452 Error: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2020.05.21 12:28:55.4452 Error: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2020.05.21 12:28:55.4452 Error: at DevExpress.CodeAnalysis.CodeCleanUp.CodeCleanUpEngine.<Apply>d__31.MoveNext()
I also attached the my CodeRush Settings.
Any ideas what I might be doing wrong or what is causing CodeRush to fail?
Thanks,
Nathan
Hi Nathan,
Thank you for reaching out to us and for your code sample. I replicated this behavior and forwarded this thread to our R&D team for further research. We will update this thread once we have any news.