Problem Converting Web To Web Project In VS2008 - asp.net

I have converted my old VS2008 Website to Web Application, now everything was working before I tried to convert it. But now I don't seem to be able to reference my Classes? For example I have a BasePage class that every .aspx page inherits like so
public partial class SomePageName : BasePage
{
}
But now I get this message? And the same for all the other classes?
The type or namespace name 'BasePage' could not be found (are you missing a using directive or an assembly reference?)
How do I find out which 'using' directive I am missing and whats an assembly reference?

The conversion namespaced your classes. Perhaps it should be NewlyAddedNamespace.BasePage?

Locate the class BasePage in your project using the object explorer.
In object explorer you will be able to see the complete name Something.Somethingelse.BasepAge
Do mass search and replace to the complete name.

In Solution Explorer (available on the View menu if you can't see it), you will see that your web application contains a node marked "References". Right click on this and choose "Add reference", and when the dialog box appears, on the Project tab you be able to add a reference to the other project which defines this BasePage class. This then becomes an assembly reference when compiled.
You probably already have the using statement you need from before. Previously, this would have been picked up by the presence of the necessary DLL in the bin folder of the web project. It works differently for a web application.

How to convert in a Web Site Project - will get you started - it is for VS2005 but will still be applicable for Visual Studio 2008.
You might want to take a look at the difference between the 2 types of projects. That said, website projects generally are not created with namespaces, I would guess that "BasePage" was in you appCode folder and has now been converted into a different namespace. You just need to line you your namespaces and everything should work correctly.

What you could try is "Convert to Web Application" in Visual Studio. It is available in the context menu of the new Web Application project in Visual Studio.

There's another possible issue. You might need to set the "Build Action" to "Compile instead of Content. Right-click the .cs file, bring up the properties and make sure the Build Action is compile.

Related

.net library class not updated in web page

I just created a new web site in Visual Studio 2012. I also created a new Class Library. I added a class, another class inside that first class and then a method. I compiled the library and added as the reference in the bin folder for the web site.
In a aspx.cs page I can now see my new method. Great. I go to create a second method in the same location, go back in my aspx.cs page, can't see it. It says there is definition for this method.
I compile the class library just in case. Can't see it. I clean the solution, build the whole solution, still can't see it.
I actually have to remove the reference from the bin folder of the web site and add it back so that now I can see the second method.
I worked on another project where (I believe) things were set up the same way (web site + class library) and by typing the new method in the class and saving the file was enough to reach this method from an aspx page.
What can I change in my solution so that the new method in the class library can be seen directly?
ps: the aspx.cs page has using myLibrary; at the top;
Thanks
Make sure in your solution that you are using the References folder. Right-click it, choose "Add Reference" and then use the Solution tab to reference your class library project. Taking this approach, every time you update your class library the web project will automatically receive the update.
It sounds like you might be adding the binary to the BIN folder of the website project and then referencing it from there?
First of all check if build is going to debug folder or bin folder. If you are referencing project then make sure that build order is correct and dependency set accordingly. Also check for class library or project referred solution is not building on client profile, select targeted framework.

Copying/Moving App Code to New Project

Ok, I am in the process of breaking apart of intranet application (VS 2010 Web Site, ASP.NET Web Forms with VB code behind). During this process i'm trying to convert some of our our app_code files in to WCF rest service in a new project. However, when I copy or "add existing" vb files into the new "services" project. I get tons of errors including...
error BC30002: Type 'XXX' is not defined
warning BC40056: Namespace
or type specified in the Imports 'System.ServiceModel' doesn't
contain any public member or cannot be found. Make sure the
namespace or the type is defined and contains at least one public
member. Make sure the imported element name doesn't use any aliases.
From what i've read it may (or may not) have something to do with Assemblies and references that I just have very little knowledge on. I have added the namespaces from the current web.config to new project's web.config, and the files are identical. So there is something in the background that needs to be added to the new project I just don't know what its.
PLEASE HELP!!
THANKS
JOSH
UPDATE 1
So one of the errors i'm getting = "error BC30002: Type 'MailMessage' is not defined." Which is a namespace that is added to the web.config, which apparently isn't being picked up??? IDEAS?
I've come across a similar issue - not sure what the reasoning behind it is, but I got around it by creating a new .vb class with the same name as the one you want to copy, then copy and paste all the text from the old one to the new one. Save it, then it seems to like it - it didn't like me copying and pasting the actual file, nor did it like me adding existing files.
Hope this helps :/
This issue seems to be tied to the the differences between Web Application Projects versus Web Site Projects. Eventually I had to add different namespaces on the new project level.
Here is more info about WAP vs WSP....
http://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

Parser Error in ASP.NET Web Application

I have inherited a Web Application project (3 files per aspx page), along with a second solution which contains the business and datalayers as a class library. I created an empty solution, added the class library project to it, along with the Web Application. I then added a reference to the class library from the Web Application. When I try to debug the site, I get a parser error:
Parser Error Message: The type 'Electro_Spec.Masters.MasterPage' is ambiguous: it could come from assembly 'C:\projects\esWOT3\WebSite\bin\Electro-Spec.DLL' or from assembly 'C:\projects\esWOT3\WebSite\bin\WebSite.DLL'. Please specify the assembly explicitly in the type name.
Why would this be? And how do I fix it?
EDIT the only reference to Electo_Spec.dll is from the Web Application "refrences", the class library was added to the site via the add reference to existing project dialogue. If I remove it, the site won't compile. Additionally the name of the web application is WebSite . . . thus the "Website.dll" . . . i believe, as I am new to web applicaitons (versus .net websites). Oh and this was all built in an empty solution. Additionally I have tried renaming the MasterPage to MasterPage1 to no avail.
The Electro_Spec.Masters.MasterPage class is defined in both projects.
Remove the Electro_Spec.Masters.MasterPage from one of the two projects or change the namespace for one of the two MasterPage classes.
Well, there's a type with the same name (Type.FullName) in those two assemblies. Are you sure those assemblies are not the same? If they are, delete one. If they are not, add the assembly name to the Inherits attribute, like: Inherits="Electro_Spec.Masters.MasterPage, Electro-Spec"

How to convert ASP.NET website to ASP.NET web application

I have an ASP.NET 3.5 Website (visual studio lingo), but the site continues to grow and is looking rather cowboyish among other things. I'd like to see this get converted into a Web Application (namespaces and all).
Is this something that can be easily done in Visual Studio? If not, are there any other tools out there that could create all of the namespaces, etc. automagically?
Well, it turns out that the option "Convert to web application" does NOT exist for "websites". The option "Convert to web application" does exist only for "web applications" !!!!
[emphasis mine]
So, here's the deal, to do the
conversion, you need to:
Add a new "Web Application" to your VS 2008 solution (File->Add->New
Project->C#->Web->ASP.NET Web
Application).
Afterwards, you copy all the files in the old "website" to your newly
created "web application", and
override any files created in it by
default
The next step is the most ugly, you need to "manually" add the references
in your "website" to the new "web
application". I thought the VS 2008
PowerCommands toy would do this for me
as it does copy references from other
project types, but it didn't. You have
to do it by yourself, manually, and
you have to be cautious in this step
if you have multiple versions of the
same assembly (like AJAXToolkit in my
case) or assemblies that have both GAC
and local versions or so.
Keep repeating the last step and trying to build the "web application".
You'll keep getting errors like "
'....' is unknown namespace. Are you
missing an assembly reference? ". Make
sure you have none of those except the
ones where '....' is replaced by the
IDs of the server controls you use. In
other words, keep adding references
and building the project until only
the errors that exist because of
missing .DESIGNER.CS or .DESIGNER.VB
files.
Afterwards, go to the "web application" root project node in VS
2008 solution explorer, and right
click it, then you WILL find the
option "Convert to web application".
What this option does is actually
making small changes to the "#Page"
and "#Control" directives of pages and
controls, and creating the required
.DESIGNER.CS or .DESIGNER.VB files.
Try building the "web application" again. If you get errors, see what
references may be missing and/or go
click the "Convert to web application"
again. Sometimes, if there's any error
other than those caused of missing
DESIGNER files, not all the
pages/controls will have those
DESIGNER files created for them.
Fixing the non DESIGNER problem and
clicking "Convert to web application"
again should do the job for this.
Once you are done successful VS build, you should be ready to go.
Start testing your web application.
Optionally, you can right click the
"web application" root project node in
VS 2008 Solution Explorer and click
"Properties" then go to the tab "Web"
to set the "web application" to a
virtual folder in IIS (you can create
new virtual directory from there in
VS). If you want to use the IIS
virtual directory that the old
"website" used, you need to remove
that from IIS first.
Update: When testing your pages, pay MOST ATTENTION to classes in
"App_Code" folder, especially those
with NO NAMESPACE. Those can be a big
trap. We had a problem with two
extension method overloads in the same
static class that had no namespace,one
extends DateTime? (Nullable)
and calls another overload that
extends DateTime itself. Calling the
other overload as extension method
passed VS 2008 compilation and gave us
a compilation error ONLY IN RUNTIME
(With IIS). Changing the call to the
other overload from calling it as
extension method to calling it as
normal static method (only changing
the call in the same class, calls from
other classes remained extension
method calls) did solve this one, but
clearly, it's not as safe as it used
to be in VS 2005. Especially with
classes with no namespaces.
Update2: During the conversion, VS 2008 renames your "App_Code" to
"Old_App_Code". This new name sounds
ugly, but DO NOT RENAME IT BACK. In
the "web application" model, all code
will be in one assembly. In runtime,
the web server does not know what web
project type you are using. It does
take all code in "App_Code" folder and
create a new assembly for it. This
way, if you have code in folder named
"App_Code", you'll end up with RUNTIME
compilation errors that the same types
exist in two assemblies, the one
created by VS, and the one created by
IIS / ASP.NET Development Server. To
avoid that. leave the "Old_App_Code"
with the same name, or rename it to
ANYTHING EXCEPT: "App_Code". Do not
place any code in such "App_Code"
folder and prefereably do NOT have a
folder with such name in your "web
application" at all.
I know this since before but forgot it
now as I have not used "website" model
for long :(.
Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio at MSDN
If your website application grows.. it's better to split it into several projects. Conversion from Web Site project to Web Application project won't help much.
If you're having problems getting your new Web Application Project to build check the File Properties in Visual Studio of all 'helper' classes. For a project I was converting the Build Action was set to Content whereas it should have been Compile.
I've now successfully migrated one Website project to a web application and there is quiet a few gotchas to look out for.
Having ReSharper at your disposal helps a lot in refactoring the aspx files.
Set up your solution and create an empty WebApplication
Copy all file over
aspx files in website projects don't have a namspace. Wrap your classes in the appropriate namespaces
During copying, all my pages in subfolders got renamed to my project name and the foldername, so I got 40ish public partial class FolderName_Projectname : Page If neccessary rename all files using Resharper or manually.
If you encounter multiple errors like "There is already a member Page_Load() defined", this is most likely due to incorrect class names und duplication
After adding a namespace
Replace CodeFile in all aspx pages with Codebehind and especially pay attention to files i your subfolder. Make sure Inhertis="" doesn't contain the relative path. Your namespaces take care of everything. So the correct format is Inherits="Namespace.classname".
If your class has a namespace NaSpa and a filename foo.cs it would be Inherits="NaSpa.foo"
After you have prepared all your files (don't forget your master pages), run "Convert to web application". If you encounter errors afterwards, rinse and repeat.
If you encounter errors of the sort "TextBoxName can't be found are you missing a reference", make sure you did not forget to sanitize your aspx pages. A good indicator is to check the automatically generated designer files. If TextBoxName does not appear in there, the conversion did not succeed completely.
Resolve any missing dependencies.
Build
Create a New Web Application in VS 2010.
1. Using Windows Explorer copy all your files into you project folder.
2. In VS 2010 solution explorer show all files.
3. Select the files and folders - right click include in project.
4. Right click the project solution explorer and select Convert to Web Application.
There are quite a few small differences, such as the App_Code folder will get renamed to old_app_code - that surprisingly doesn't cause any errors. The TypeName on your object data sources and the inherits on the #Page tag might need the [ProjectName]. prefix appended globally. For example if your type name was "BusinessLogic.OrderManager" and your project name is InventorySystem you would need to change it to InventorySystem.BusinessLogic.OrderManager. Also a few display changes, such as required field validators don't default to red font anymore, they default to black.
I was facing the same problems initially. After following the Wrox Professional ASP.NET 4.0 book, I found the following solution for my case.
I first created a new web application. Copied all the website files into the web application folder. Right click on the application, and click conver to web application.
You might ask why you need to convert a web app into a web app. The answer is, that when you create a website, you simply code the .cs file where-ever required.
A web application, however declares .design.cs (or .vb) and a .cs file for the code and design section automatically.
NEXT: Remove all manual references, like 'Inherits' attribute in the PAGE directive, to other files in your website, since name spaces WILL take care of referencing the classes centrally.
I also faced a problem, since I had not included OBJ and BIN folder in my project.
If you think you are missing your BIN and OBJ folders, simply click the 'Show All Files' icon in the Solution Explorer and then right click on the missing folders and add to project. (to make sure they compile with the project.)
UPDATE:
As #deadlychambers points out in the comments: You can search everywhere by doing a "Ctrl + Shift + F" and then search for Inherits="(.*?)". This will find all occurrences and probably save you some time!
the default ASP name space does not seem to work anymore. So I cannot seem to call my User Controls.ascx pages from outside the page. Giving them a namespace and changing the default from ASP to my namespace seemed to work.

Casting error in ASP.NET

I have a class declared in the App_Code folder. The class contains a public shared method that returns a type Portfolio.
When I try to call this method to initialize an object of type Portfolio in one of the ASCX controls, i get a "Value of type Jaguar.Portfolio cannot be converted to Jaguar.Portfolio" message.
This is a "Website" project. I have tried using CType and DirectCast and I still get the same compilation error when I try to build the site.
I am using the line of code listed below in the code behind file of the ascx control
Dim pObjSvc As Jaguar.Portfolio = ClassName.GetPortfolio
Do you have a webpage or a user control also called Portfolio? You may have a name space collision where it's confused between which Portfolio object to use. If this is the case, you'll need to change the name of the Class/Module or the control's or page's code behind class and you should be all set.
There seems to be someone else with the same problem out there:
ASP Net - value of type "MyNamespace.MyClassName" cannot be converted to "MyNamespace.MyClassName"
I have a ASP.Net application that uses
assemblies from several other
solutions. When testing the
applications on my machine I build all
the referenced assemblies using nmake.
The latest assemblies get placed in a
common directory that is referenced by
my ASP.NET app.
Occasionally I receive the following
error: value of type
"MyNamespace.MyClassName" cannot be
converted to "MyNamespace.MyClassName"
(there are a lot of these for
different classes) when doing a debug
build. I have tried the following with
no luck:
Build the ASP.Net application Rebuild
the ASP.Net application Close VS and
build the ASP.Net application Close
VS.Net as rebuild the asp.Net
application IISreset and build/rebuild
the application
It seems the only thing that works is
if I run nmake to build all my referenced assemblies, I can then
build the ASP.Net application.
Any ideas as to what causes this? Is
there an easier way to fix it?
Sadly, the author of the question did non find a definitive answer. But perhaps it contains a hint which could be helpful to find the solution.
UPDATE: I'm not sure if that is even possible in a ASP.NET website, but maybe you accidentally added a reference to a (temporary) assemmbly of the project itself? That would explain the error. Try also to remove the contents of bin and obj folder.
Just a debugging tip:
Try to rename the Portfolio class and recompile. Maybe there is an old assembly somewhere or some other code in .vb your files which contains a class with the same name?
I have seen situations similar to this when an aspx page was created with the same name as a business object class. Do you have some some aspx page with a code-behind class of Portfolio as well?

Resources