Search code examples
vb.netwinformscompiler-errorsvisual-studio-2015eazfuscator

Why is Visual Studio 2015 failing with error code BC30506


I have a very large project that I have moved from Visual Studio 2012 to 2015 about a month ago.

The code is sound. It compiles 99.9999% of the time, except for the last two days I have had this random occurrence.

I am using an obfuscator (Eazfuscator paid version) to build the solution.

For the last two days, I am able to work, everything compiles over and over again and works just fine, but when I go to compile the project in obfuscated mode, SOMETIMES, the compiler fails, and fills the Error List with the following:

Severity Code Description Project File Line Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmHome.vb 719 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 5 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 9 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 13 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 17 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 38 Error
BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. wRMS D:_Private\wRMS\wRMS_Miscellaneous Forms\Main Application\frmUpdate.vb 42 Blockquote

Clicking Clean from the Build menu does not change anything.

I have numerous custom controls (buttons, checkboxes, lists, etc.) that I have created and use on the forms. Eazfuscator obfuscates the names of those controls during compilation, which makes the forms no longer viewable in the designer (this has always been a symptom); but now the IDE wont let me rebuild the solution once it has been obfuscated if I see the above errors, and I cannot even rebuild it NON-obfuscated. I'm just stuck.

Unfortunately when this happens, the project wont compile ever again, I have to basically restore the project from back ups and lose my work.

What is causing this? What can I do? Can I somehow clear the solution so the IDE just rebuilds directly from source and doesn't look at the obfuscated output at all?


Solution

  • The problem is with VS2015, you cannot obfuscate an assembly in debug mode, the IDE will "freak out" because the user control's object name has been changed to gibberish. It will delete the controls, and for some reason even standard WinForms controls around it.

    The solution is to only allow your obfuscator to obfuscate when in release mode, by editing your post-build event to say something like this (depending on your obfuscator):

    if /I "$(ConfigurationName)" == "Release" Eazfuscator.NET.exe "$(TargetPath)" --msbuild-project-path "$(ProjectPath)" --msbuild-project-configuration "$(ConfigurationName)" --msbuild-project-platform "$(PlatformName)" --msbuild-solution-path "$(SolutionPath)" -n --newline-flush -v 5.1
    

    Unfortunately if you've stumbled on this problem, your source code is nuked, and you do have to restore from backup.

    Have some DevOps in place and constant backups; since permanently specifying the statement:

    if /I "$(ConfigurationName)" == "Release" 
    

    Seems to have fixed my issues permanently.

    Microsoft has been notified, as well as EAZfuscator

    https://connect.microsoft.com/VisualStudio/feedback/details/1833336/obfuscated-assembly-in-debug-mode-causes-ide-to-delete-winforms-controls

    UPDATE 2017: Coming back here two years later, it is worth noting that you need to PAY ATTENTION to your IDE. If you last built in Release mode (and obviously the assembly was obfuscated), DO NOT open any FORM until you rebuild in Debug mode first. Debug mode will reset the assembly state to unobfuscated, and you can view your forms without issue.

    If you accidentally open a form in obfuscated Release mode and it breaks on display, simply close every window out inside the IDE, leaving the IDE open, and rebuild in Debug mode. Now you can continue without issues.