When converting a project from C# to VB I ran into this compiler error which stopped me in my tracks for about 15 minutes. Just when I gave up and decided to rebuild the page by hand inspiration hit and I found my solution...
I had just put the finishing touches to a domain whois tool and I was ready to convert it over to a VB project. I'm not a very strong VB.net coder but the project required the final deliverable in VB so I opted to make it all in C# first and then convert it over using one of the great free tools for converting code online.
After creating my new solution, adding the website and the class library, creating the stub pages and running all of the code files through the online code converter I was almost ready to go.
The last step was to convert the aspx ui page. I was vaguely aware that in some situations there are differences between the syntax in these pages but I kept my fingers crossed that I wouldn't have to remember these little nuances so I could ship it quickly.
Hitting compile I was hit with the an error which confused me:
Error 1 'srcDomainMulti' is not declared. It may be inaccessible due to its protection level.
Double clicking it took me to a line in my code behind where I was tweaking a parameter of an ObjectDataSource just before it bound. The code couldn't see the ObjectDataSource on my page!
I played around for a few minutes, even rolling up my sleeves and writing some code to FindControl it just in case it was a naming container issue I was unaware of:
Dim srcMulti As ObjectDataSource = DirectCast(Me.FindControl("srcDomainMulti"), ObjectDataSource) srcMulti.SelectParameters("PopularOnly").DefaultValue = "False"
But the page still didn't work. In the end I gave up and started recreating the page by dropping controls onto a new VB page and setting them up item by item. When it came to binding the first drop down list I noticed something odd. The namespace of my DataObject was listed as:
The solution was really straightforward in the end, as nearly all problems turn out. Without looking into this too deeply it seems that VB holds your hand when it comes to namespaces and automatically wraps the class libraries files in a namespace.
Each of the .vb files I had run through the converter also had a namespace declaration wrapped around them which was doubling up on my code and making everything invisible.
I whipped through the project removing all my namespace wrappers which removed the middle namespace layer, pressed compile and the project worked without any further grumbles!