'var_name'is not declared. It may be inaccessible due to its protection level.' in debug mode

后端 未结 4 1683
面向向阳花
面向向阳花 2020-12-18 23:33

This behavior is in a vb.net web application solution with multiple class library projects referenced by the web app.

The code compiles, but in debug mode, some func

相关标签:
4条回答
  • 2020-12-18 23:59

    It's not exactly a permanent solution, but I did find a workaround for this in a project I was amending for a friend of mine. Although I couldn't make the bug to go away on a permanent basis, I found that it didn't report these errors if the affected pages weren't actually open for editing.

    What I had to do was save them, close them out of the editor, and then compile the project. The project WOULD compile correctly once I'd done that, and after it had compiled, it wouldn't report those errors again even once the pages were opened for editing (though eventually, some edit or other would cause the problem to reoccur -- but each time, the solution was the same. Close everything out, compile, and then reopen whatever I need to edit.)

    0 讨论(0)
  • 2020-12-19 00:03

    A few months back I was dealing with exact same issue in VS2013. It is a maddening bug that Microsoft is (last I saw) unable to reproduce. For me, it came and went with no apparent reason. The first few times I got rid of it by doing some of the things you have already tried above. But then it came back and I could not get rid of it. What finally did the trick was uninstalling and removing all traces of all versions of Visual Studio (including a manual sweep of the registry), getting rid of all code, projects, solutions, etc, and removing all versions of .NET.

    Then I put .NET back, re-installed VS2013, and got latest from TFS. Since then, it has not come back. Sure hope it doesn't. Good luck!

    0 讨论(0)
  • 2020-12-19 00:08

    When it comes to a WinsForm app written in VB.NET, this can happen if the backing code file for the "{Whatever_Form}.vb [Design]" tab, {Whatever_Form}.designer.vb code file, is corrupted by the Visual Studio designer logic. The control symbol that is supposedly "...not declared. It may be inaccessible..." is declared at the wrong scope within Sub InitializeComponent() within the {Whatever_Form}.designer.vb code file, the "Me." prefix is missing, "Friend WithEvents Foo As Type" statement is missing and/or all of the above. The way to fix it is to directly edit the {Whatever_Form}.designer.vb code file leaving the correct {Whatever_Form}.vb source untouched. Edit all the inconsistent declarations having to do with the symbol of the {Whatever_Form}.designer.vb code file which is listed out using the "Find in Files" Visual Studio menu item.

    One thing to avoid to not cause this type of corruption is to not rename the control symbol's property names "(Name)" or event handler procedure names using the Visual Studio Properties tab. Rename symbols from the {Whatever_Form}.vb source file only.

    I using Visual Studio 2017 Pro, for a VB.NET WinsForm app targeting .NET Framework 4.7.1.

    0 讨论(0)
  • 2020-12-19 00:16

    Try to CleanSolution, it appeared to fix it for me.

    0 讨论(0)
提交回复
热议问题