简体   繁体   中英

Visual Studio 2017 VB.NET error BC30451: 'variable' is not declared. It may be inaccessible due to its protection level

I'm pulling my hair out over this one: I recently upgraded a project solution to VS 2017. At first all went well, then 'something happened'. I have no idea what happened but now I cannot declare variables in local routines anymore.

For example, I have some variables in a button click event. I try and add 'Dim testvar as string ="XXXX" and all seems well, no compile or syntax errors but if I break at the line of code below the Dim statement and then try and do a Quickwatch on the variable it displays an error, saying: 'error BC30451: 'testvar' is not declared. It may be inaccessible due to its protection level.'

Nothing I do to the project gets rid of this error - except if I declare it at the top under the Public Class statement ie raise its scope to form level instead of at the click event routine level.

What have I done?

And why is VS2017 so fragile?

It honestly seems to me that sometimes you've only got to look at it funny and it breaks!

So anyway, as I mentioned I got round this issue by actually using the variable in question and the error goes away. I suspect the error it displays is trying to tell me that it hasn't been used yet but it's a baffling error when you just need to get work done. Thanks for your help anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM