0

我有两个项目“HOD”和“控制器”。Controllers 是一个命名空间为“Controllers”的类库。在 HOD 的代码文件中,我试图通过“使用控制器”来引用控制器命名空间。我在 HOD 项目中添加了对 Controllers 的引用,它确实显示在 VS2008 中的引用文件夹下。

当我构建项目时,我没有收到任何错误,但是当我去查看页面时,我收到错误“找不到类型或命名空间名称“控制器”(您是否缺少 using 指令或程序集引用?)” .

Controllers.cs(类库,控制器项目)

using System;
using System.Collections.Generic;
using System.Text;

namespace Controllers
{

    public class Controller {    }

}

index.aspx.cs(HOD 项目)

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Controllers;


public partial class HOD : Page
{

    string sop() { return "sop"; }

    protected void Page_Load(object sender, EventArgs e)
    {
        blahmsg.Text = sop();
    }

}

该项目位于我们的网络服务器上,Controllers.dll 与 HOD.dll 位于同一 bin 文件夹中。在此先感谢您的帮助!

编辑:.sln 内容

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "T:", "T:\", "{1D5F28B3-E6A0-4CF8-B7A3-43121225C73E}"
    ProjectSection(WebsiteProperties) = preProject
    TargetFramework = "2.0"
    Debug.AspNetCompiler.VirtualPath = "/T:"
    Debug.AspNetCompiler.PhysicalPath = "T:\"
        Debug.AspNetCompiler.TargetPath = "E:\DEV\webdev\webdev\PrecompiledWeb\T:\"
        Debug.AspNetCompiler.Updateable = "true"
        Debug.AspNetCompiler.ForceOverwrite = "true"
        Debug.AspNetCompiler.FixedNames = "false"
        Debug.AspNetCompiler.Debug = "True"
        Release.AspNetCompiler.VirtualPath = "/T:"
        Release.AspNetCompiler.PhysicalPath = "T:\"
        Release.AspNetCompiler.TargetPath = "E:\DEV\webdev\webdev\PrecompiledWeb\T:\"
        Release.AspNetCompiler.Updateable = "true"
        Release.AspNetCompiler.ForceOverwrite = "true"
        Release.AspNetCompiler.FixedNames = "false"
        Release.AspNetCompiler.Debug = "False"
        VWDPort = "53327"
    EndProjectSection
EndProject

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HOD", "Y:\HOD\HOD.csproj", "{5F523FB7-B902-4E6E-BAA9-C2EB37D69EC7}"
EndProject

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controllers", "Y:\HOD\Controllers\Controllers.csproj", "{E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {C8A12BBE-4483-4560-97A4-795F2E57D667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {C8A12BBE-4483-4560-97A4-795F2E57D667}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {C8A12BBE-4483-4560-97A4-795F2E57D667}.Release|Any CPU.ActiveCfg = Debug|Any CPU
        {C8A12BBE-4483-4560-97A4-795F2E57D667}.Release|Any CPU.Build.0 = Debug|Any CPU
        {A81C381B-1E12-49B0-8BC0-8532EF9F216F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {A81C381B-1E12-49B0-8BC0-8532EF9F216F}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {A81C381B-1E12-49B0-8BC0-8532EF9F216F}.Release|Any CPU.ActiveCfg = Debug|Any CPU
        {A81C381B-1E12-49B0-8BC0-8532EF9F216F}.Release|Any CPU.Build.0 = Debug|Any CPU
        {BD46969E-9D1C-419A-A82C-388E35BF7C13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {BD46969E-9D1C-419A-A82C-388E35BF7C13}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {BD46969E-9D1C-419A-A82C-388E35BF7C13}.Release|Any CPU.ActiveCfg = Debug|Any CPU
        {BD46969E-9D1C-419A-A82C-388E35BF7C13}.Release|Any CPU.Build.0 = Debug|Any CPU
        {1D5F28B3-E6A0-4CF8-B7A3-43121225C73E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {1D5F28B3-E6A0-4CF8-B7A3-43121225C73E}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {1D5F28B3-E6A0-4CF8-B7A3-43121225C73E}.Release|Any CPU.ActiveCfg = Debug|Any CPU
        {1D5F28B3-E6A0-4CF8-B7A3-43121225C73E}.Release|Any CPU.Build.0 = Debug|Any CPU
        {5F523FB7-B902-4E6E-BAA9-C2EB37D69EC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {5F523FB7-B902-4E6E-BAA9-C2EB37D69EC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {5F523FB7-B902-4E6E-BAA9-C2EB37D69EC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {5F523FB7-B902-4E6E-BAA9-C2EB37D69EC7}.Release|Any CPU.Build.0 = Release|Any CPU
        {E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

编译器输出

------ 重建所有开始:项目:控制器,配置:调试任何 CPU ------ C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701, 1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C :\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C: \Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Controllers.dll /目标:库 Class1.cs 属性\AssemblyInfo.cs

编译完成 -- 0 个错误,0 个警告 Controllers -> Y:\HOD2\Controllers\bin\Debug\Controllers.dll ------ Rebuild All started: Project: HOD, Configuration: Debug Any CPU ----- - C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:Y:\HOD2\Controllers \bin\Debug\Controllers.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Configuration.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework \v3.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows \Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft。NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll /reference:C:\Windows\Microsoft.NET\Framework\ v2.0.50727\System.Web.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.Design.dll" /reference:"C:\程序文件 (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Web.Extensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Mobile.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference :"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /optimize- /out:obj\Debug\HOD.dll /目标:库 index.aspx.cs index.aspx.designer.cs Properties\AssemblyInfo.cs

编译完成 -- 0 个错误,0 个警告 HOD -> Y:\HOD2\bin\HOD.dll ========== 全部重建:2 个成功,0 个失败,0 个跳过 ======= ===

4

3 回答 3

1

chelfers,感谢您在此处发布 sln 文件。根据它,您没有项目参考。

您可以从 Visual Studio 添加它(删除引用、保存、添加引用),也可以添加以下行:

ProjectReferences = "{E6A16990-5FC6-4FE3-8DAB-CD2FEC8CF4FF}|Controllers.dll;"

就在下面

ProjectSection(WebsiteProperties) = preProject
    TargetFramework = "2.0"

(为了安全起见,先复制 .sln 文件)。

PS:移动到 3.5,它是二十一世纪 :)

于 2010-03-04T19:34:52.670 回答
0

您是否会在您的服务器上运行防病毒软件?

我遇到了 aspnet_wp 无法加载 DLL 的问题,因为该文件已被服务器上的 McAffee 锁定。

修复是禁用对我们的 bin 目录的防病毒实时检查。

干杯,弗洛里安

于 2010-03-05T13:14:54.300 回答
0

我尝试使用上面列出的两个项目重新创建您的解决方案。一切都编译并工作得很好。(我假设 blahmsg 是一个 <asp:Literal/>。)

根据您发布的内容,似乎没有任何问题,这让我认为这是一个缓存问题。我会尝试清除以下内容:

  • 您的 Web 应用程序的 bin 文件夹
  • C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET 文件
  • 删除两个项目的 .csproj.user 文件。我过去曾遇到过这些原因问题。

如果这些没有帮助,我会进一步调查。您可以发布任何其他相关的源代码吗?也许是网页的标记?

于 2010-03-04T18:16:52.780 回答