question

RodAtWork avatar image
0 Votes"
RodAtWork asked AgaveJoe answered

Getting error BC30451, wondering if the module declaration is wrong

I maintain an old ASP.NET WebForms app written years ago by someone else. He wrote it using VB.NET. I'm not a VB.NET expert. I've been working on the app to make it build in our on-prem TFS. I've resolved some issues, but other issues have come up as I work on it. I came across this post in this forum, which helped: Error BC30451 'xxxxxxx' is not declared. It may be inaccessible due to its protection level

However, I'm still getting the error. In the reference link it was suggested that since the app the poster was discussing was a Web Site app, that there might be issues. The app I'm maintaining has an App_Start folder in it, which I guess suggests this might have been a Web Site app, instead of a Web Application app. I've moved the 3 .vb files out of App_Start, putting them all in the root level of the web application. However, I'm still getting the BC30451 error:

140255-screenshot-2021-10-13-102220.png

This is where my inexperience at VB.NET comes into play. The method RegisterRoutes is in a RouteConfig.vb file, which is a module file. As I understand it, Modules in VB.NET are analogous to static classes in C#. Here's RouteConfig.vb:


 Imports System.Web.Routing
 Imports Microsoft.AspNet.FriendlyUrls
    
 Public Module RouteConfig
     Public Sub RegisterRoutes(ByVal routes As RouteCollection)
         Dim settings = New FriendlyUrlSettings()
         settings.AutoRedirectMode = RedirectMode.Permanent
         routes.EnableFriendlyUrls(CType(settings, FriendlyUrlSettings))
     End Sub
    
 End Module

I had thought that RegisterRoutes might need to be declared using Shared, which I think is like static in C#. I tried that, but VS 2019 indicated to me that was wrong, so I removed it. Should there be some other declaration I should apply to RegisterRoutes to make it visible to Global.asax?



dotnet-visual-basicdotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered RodAtWork commented

Hi @RodAtWork,
Maybe you can create a new project, replace the files in the App_Start folder, and rebuild.
Best regards,
Lan Huang


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @LanHuang-MSFT,

That's a good idea. I've created a new VB.NET ASP.NET WebForms app. I've done nothing with it, other than made sure it also uses .NET 4.5.2, just like the app I'm working with does. This new app I called SimpleVBWebForms. It builds and runs fine.

Then I copied the BundleConfig.vb and RouteConfig.vb files from SimpleVBWebForms's App_Start folder, to the application I've been working on (Timetrack), into Timetrack's App_Start folder. However, the Timetrack app doesn't like the definition of RouteConfig.vb. Here's how RegisterRoutes() is defined in RouteConfig.vb, in SimpleVBWEbForms:

 Public Module RouteConfig
     Sub RegisterRoutes(ByVal routes As RouteCollection)
         Dim settings As FriendlyUrlSettings = New FriendlyUrlSettings() With {
             .AutoRedirectMode = RedirectMode.Permanent
         }
         routes.EnableFriendlyUrls(settings)
     End Sub
 End Module

Like I said, this builds and runs fine, in SimpleVBWebForms. However, Timetrack complained when I put that code in, with the line:

 routes.EnableFriendlyUrls(settings)

VS 2019 said that EnableFrientlyUrls couldn't be resolved. It gave an error of BC30519:

0 Votes 0 ·

(Cont.)

The error was:

BC30519 Overload resolution failed because no accessible 'EnableFriendlyUrls' can be called without a narrowing conversion:
Extension method 'Public Sub EnableFriendlyUrls(settings As FriendlyUrlSettings)' defined in 'RouteCollectionExtensions': Argument matching parameter 'settings' narrows from 'Object' to 'FriendlyUrlSettings'.
Extension method 'Public Sub EnableFriendlyUrls(ParamArray resolvers As IFriendlyUrlResolver())' defined in 'RouteCollectionExtensions': Argument matching parameter 'resolvers' narrows from 'Object' to 'IFriendlyUrlResolver'.

I'm thinking there's an issue with System.Web.Routing. Looking at SimpleVBWebForms's properties, References, I can see System.Web.Routing is imported/selected in the lower section of the References pane. However, in Timetrack's properties, in the References pane, System.Web.Routing is not selected/imported. And I cannot check the checkbox next to it to select/import it.

What do you recommend?

0 Votes 0 ·
AgaveJoe avatar image
0 Votes"
AgaveJoe answered

The community's recommendation to create a sample project is so you can review the RouteConfig.cs code and understand why you are receiving the complier errors. You can't mindlessly copy the RouteConfig.cs from the Visual Studio template to source code. You run the risk of messing up the project for the next developer.

You need the original source code or the project requirements to rewrite the source code. If you cannot find all the source code or decompile the DLLs on the server, then backup the production application if not done so already. Let your boss know the source control project is not going to happen because you are missing the source code.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.