codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.92k stars 363 forks source link

Exception thrown during cleanup #526

Open markusschwamberger opened 6 years ago

markusschwamberger commented 6 years ago

Environment

Description

Two exceptions are thrown when i try to perform Cleanup Active Document:

[CodeMaid Handled Exception 08:52:54 ] TryDefault caught an exception on 'System.Func1[System.Boolean]': System.Runtime.InteropServices.COMException (0x8000FFFF): Schwerwiegender Fehler (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.Exceptions.ThrowEUnexpected() at Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel.VisualBasicCodeModelService.GetFunctionKind(IMethodSymbol symbol) at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.CodeFunction.get_FunctionKind() at EnvDTE80.CodeFunction2.get_FunctionKind() at SteveCadwallader.CodeMaid.Model.CodeItems.CodeItemMethod.<.ctor>b__6_4() at SteveCadwallader.CodeMaid.Model.CodeItems.BaseCodeItemElement.TryDefault[T](Func1 func) [CodeMaid Handled Exception 08:52:54 ] TryDefault caught an exception on 'System.Func1[System.Boolean]': System.Runtime.InteropServices.COMException (0x8000FFFF): Schwerwiegender Fehler (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.Exceptions.ThrowEUnexpected() at Microsoft.VisualStudio.LanguageServices.VisualBasic.CodeModel.VisualBasicCodeModelService.GetFunctionKind(IMethodSymbol symbol) at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.CodeFunction.get_FunctionKind() at EnvDTE80.CodeFunction2.get_FunctionKind() at SteveCadwallader.CodeMaid.Model.CodeItems.CodeItemMethod.<.ctor>b__6_5() at SteveCadwallader.CodeMaid.Model.CodeItems.BaseCodeItemElement.TryDefault[T](Func1 func)

The .vb file has > 2000 lines of code. Smaler files work just fine...

Steps to recreate

  1. Open "large" .vb file
  2. Click "Cleanup Active Document"

Current behavior

Exceptions is thrown and no cleanup happend :(

Expected behavior

No exception and clean file

codecadwallader commented 6 years ago

The error message looks like a specific problem with one of the method definitions within the file that is causing the error. Can you either:

  1. Provide a minimal solution that includes that file.
  2. If you don't want to share the file (understandable), then narrow down to the code segment that is causing the issue. A good way to do this would be remove half the file content, see if the issue still happens. Whenever it does, continue by removing another half. Whenever it does not, reverse the change and remove the other half. Rinse and repeat until you get down to the relevant code that is causing the error.
markusschwamberger commented 6 years ago

This Method is causing the error:

`Public Shared Widening Operator CType(auftrag As AuftragObject) As Vorbeschaeftigung Dim result = New Vorbeschaeftigung result.VertragId = auftrag.VertragID result.Id = -1 result.IstVorbeschaeftigung = True result.KDID = auftrag.KDID result.KID = auftrag.KID result.MAID = auftrag.MAID ' Auftragsende muss bei alten Aufträgen nicht unbedingt befüllt sein Dim ende = If(auftrag.Vertragsende.HasValue, auftrag.Vertragsende, auftrag.MaxVertragsende) result.Zeitraum = New DateRange(auftrag.Vertragsbeginn.GetValueOrDefault(), ende.GetValueOrDefault())

        Return result
    End Operator

`

codecadwallader commented 6 years ago

Thanks for providing the method. I'm not familiar with overriding operators in VB so when I just drop it into a console project it isn't valid. Can you provide a minimal solution that includes this method?