Reputation:
I'm getting really stuck trying to refer to methods/classes in a project imported into a blank project. The exact steps to recreate this are as follows
If you now build and run the project runs fine with no errors.
5 In VS solution explorer, for all of the imported files right click and select Include in Project
Now try rebuilding the project I get the error
The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
GetAdminMasterPage.cs is located in WebApplication1\App_Code\class\GetAdminMasterPage.cs
and looks like this
#region using references
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Web.UI;
#endregion
/// <summary>
/// Gets the MasterPage for the user selected Admin Theme.
/// </summary>
public class GetAdminMasterPage : System.Web.UI.Page
{
#region Get Admin MasterPage
protected override void OnPreInit(EventArgs e)
{
if (Cache["cachedAdminMaster"] == null)
{
GetDefaultMasterPage();
}
else
{
string loadMasterFromCache = Cache["cachedAdminMaster"].ToString();
Page.MasterPageFile = loadMasterFromCache;
}
}
private void GetDefaultMasterPage()
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbMyCMSConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_admin_SelectMasterPage", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.SingleResult);
if (myReader.Read())
{
string masterPageFileName = myReader["ThemeUrl"] as string;
Cache.Insert("cachedAdminMaster", masterPageFileName, null, DateTime.Now.AddSeconds(300), System.Web.Caching.Cache.NoSlidingExpiration);
Page.MasterPageFile = masterPageFileName;
}
myReader.Close();
con.Close();
con.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
#endregion
}
An example of one of the methods that now gives an error is
using System;
public partial class admin_admin_edit_css : GetAdminMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
//gives error The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
So I know I must refer to GetAdminMasterPage with Using xxxxxx;
but just can't figure out the correct syntax.
Firstly why does the error only occur when I select "Include In Project" and not when just copied?
Secondly, how do I fix the error with the correct path to the GetAdminMasterPage?
Upvotes: 1
Views: 822
Reputation: 161831
After opening the project as a web site, right-click the project and choose "Convert to Web Application". The result of the conversion is what you'll want to move to your blank project, or perhaps you'll want to leave the changes in place.
Upvotes: 2
Reputation: 9424
Note: you do not create a new project.
1.Copy the MYWSAT35 folder in a drive (for example: d:\MYWSAT35)
2.in Visual Studio go to File -> Open web site
3.select d:\MYWSAT35 and click on open
4.press F5 key to run application
Upvotes: 2
Reputation: 1952
You have to open the project as a web site.
If you are using VS2010, then it will prompt you for upgrade to .net 4.0. You can choose no.
But if you are opening in VS2012, it will open it with no prompts.
Both will build successfully.
Upvotes: 2