2

I'm responsible for maintaining a legacy ASP.NET website (not a web app) which contains a sizeable mix of VB and C#. I'm hoping to migrate the VB parts over to C# to have a bit more consistency.

Now I know you can use the <codeSubDirectories> tag in the web.config to indicate that certain code folders need to be rendered in a particular language; as discussed here a decade ago. But, from what I can tell, that's only relevant to class libraries and API controllers.

I have this Code Converter extension installed on Visual Studio, which allows you to convert one file at a time, it seems to work brilliantly in terms of converting the file. My issue is that when debugging the new code to check it's definitely doing the right thing - it doesn't seem to hit the new code behind at all.

For a proof of concept, I'm using the ascx file for my nav menu - it doesn't do anything fancy, just shows and hides some parts based on whether or not the user is in certain roles.

My process has been:

  1. Open the code behind (in this case: TopMenu.ascx.vb)

  2. Right-click anywhere in the editor panel and select the Convert To C# option.

  3. Sense check the newly generated TopMenu.ascx.cs file (it's in the right place, and seems like it should do the right thing)

  4. Change the TopMenu.ascx file to look at TopMenu.ascx.cs rather than TopMenu.ascx.vb

So now the top line is:

<%@ Control Language="C#" AutoEventWireup="false" CodeFile="TopMenu.ascx.cs" Inherits="Menus_TopMenu" %>

Which mimics the structure of other ascx files or aspx files that are looking at C# - however, when debugging the new file - it just doesn't hit the codebehind at all. Am I missing some obscure setting, or is this one of those "do it with a new file altogether" type processes?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Andrew Corrigan
  • 1,017
  • 6
  • 23

1 Answers1

0

In the end, my resolution was to rename the old file (i.e. change it to TopMenu - VB.aspx), then copy and paste it all to a new file using C#.

Andrew Corrigan
  • 1,017
  • 6
  • 23