Search code examples
c#asp.netvisual-studio-2017

Imported website into web application in visual studio gives 'Type typename already defines a member'


After importing this existing (and functional) site into Visual studio (tried 2017 and 2019 both) running .Net 4.0 I am getting a plethora of not found errors.

Codebehind pages are not able to see elements on the existing page Classes are declared to be duplicated or ambiguous Function names (both standard like Page_Load and custom) are reported as already defined.

I am sure that all these items are related. Here are the steps I followed:

  1. Created new Web Application from Visual Studio 2017 template
  2. Copied solution and csproject files into existing website folder
  3. Added files into the project
  4. Re-added references to site
  5. Set custom class .CS files to Compile
  6. Removed "unnecessary" using statements (which were already declared in web.config)
  7. Create a new ProfileCommon stub referencing ProfileBase

Beyond all this I have tried renaming a number of these functions and classes (using the rename) to create a new reference point.

Not sure what else I can do on this beyond major changes or a complete rewrite (100+ pages of code so far) by creating the new class files then copy/paste.

What other options are open to me?


Solution

  • Ok, this is is a migration project. Only you can "determine" if you want to convert from a web site to a web site application, and the time and efforts for such a migration project.

    Now, having stated the above? No question, that I prefer hands down a web site applications. Simple things like have VS compile and build the application, ability to add assemblies (and not have the mess of .dll's HAVING to be in the bin folder to resolve references - yuk!).

    And then simple things like the ability to multiple projects in one project are things I come to enjoy, and expect over the years when developing software.

    About the "only" thing going for a web site? Your deployment is oh so easy, since you can open a web page, or code behind, hit save, and you are done!

    but, this means both source code (code behind) has to be deployed to the web site. As noted, I prefer a build and compile process in VS. This does mean that to make a "minor" change, then you have to do a full re-deploy of the whole site.

    However, these benefits I like and enjoy? it not all a given that converting an existing web site to a web site application is worth the efforts. Only you can make this decision. On the other hand, you would not be doing this work unless you KNOW what you doing, and thus can determine if these efforts are worth the time.

    Such a conversion and refactoring process is somewhat beyond a simple post on SO.

    However some steps and tips are outlined here:

    https://devblogs.microsoft.com/dotnet/converting-a-web-site-project-to-a-web-application-project/

    I would consider starting over, and try the steps in above.

    There is a "convert" option outlined in above, and this can save enormous amounts of time. It has been some time since I have attempted such a conversion, and I not tested the "convert" option in vs2022, and hopefully it still exists.

    However, another possible option? Keep the site as web site.