1

空のプロジェクトにインポートされたプロジェクトのメソッド/クラスを参照しようとして、本当に行き詰まりました。これを再現する正確な手順は次のとおりです。

  1. ダウンロードして一時フォルダーhttp://mywsat.codeplex.com/に展開します。
  2. VS で新しいプロジェクトを作成します - Asp.Net 空の Web アプリケーション .NET 3.5 という名前の WebApplication1
  3. MYWSAT35 フォルダーからすべてのファイルを新しいプロジェクトにコピーします。
  4. VS ソリューション エクスプローラーで、[すべてのファイルを表示] を選択します。

ここでビルドして実行すると、プロジェクトはエラーなしで正常に実行されます。

5 VS ソリューション エクスプローラーで、インポートされたすべてのファイルを右クリックして [プロジェクトに含める] を選択します。

プロジェクトを再構築しようとすると、エラーが発生します

    The type or namespace name 'GetAdminMasterPage' could not be found 
(are you missing a using directive or an assembly reference?)

GetAdminMasterPage.cs は次の場所にWebApplication1\App_Code\class\GetAdminMasterPage.csあります。

#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
}

現在エラーが発生しているメソッドの 1 つの例は次のとおりです。

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?)

したがって、 GetAdminMasterPage を参照する必要があることはわかってUsing xxxxxx;いますが、正しい構文がわかりません。

まず、コピーしたときではなく、「プロジェクトに含める」を選択したときにのみエラーが発生するのはなぜですか?

次に、GetAdminMasterPage への正しいパスでエラーを修正するにはどうすればよいですか?

4

3 に答える 3

2

プロジェクトを Web サイトとして開いた後、プロジェクトを右クリックし、[Web アプリケーションに変換] を選択します。変換の結果は、空白のプロジェクトに移動するか、変更をそのまま残しておきたいものです。

于 2013-08-19T20:27:08.383 に答える