• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

“没办法加载类型 [Namespace].Global"让我伤心

用户头像
it1352
帮助1

问题说明

在我的 .Net 2.0 Asp.net WebForms 应用程序中,我的 Global.asax 包含以下代码:

In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code:

<%@ Application CodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %>

但是,当我构建时,我收到一个错误说明-

However when I build I get an error stating-

无法加载类型MyNamespace.Global".

Could not load type 'MyNamespace.Global'.

这似乎是因为编译器在 Global.asax 文件中看不到 MyNamespace 命名空间(在文件 Global.asax.cs 后面的代码中定义)(未在 R# 智能中显示..).结果证明这是一个非常难以破解的难题……任何帮助将不胜感激!

This seems to be because the MyNamespace namespace (defined in the code behind file Global.asax.cs) is not seen by the compiler in the Global.asax file (does not show in R# intellisence..). This turned out to be a very hard nut to crack... any help will be appreciated!

注意:Global.asax 和 Global.asax.cs 位于同一文件夹中.

Note: The Global.asax and the Global.asax.cs are located in the same folder.

注2:当使用 csc 从 vs 提示符编译时,它编译正常.

Note2: When compiling from the vs prompt with csc it compiles o.k.

正确答案

#1

我遇到的导致此问题的一种情况是,当您通过构建配置"指定构建平台时.

One situation I've encountered which caused this problem is when you specify the platform for a build through "Build Configuration".

如果你指定 x86 作为你的构建平台,visual studio 会自动分配 bin/x86/Debug 作为你这个项目的输出目录.这对于其他项目类型完全有效,但 ASP.NET 期望将程序集输出到 Bin 文件夹的 Web 应用程序除外.

If you specify x86 as your build platform, visual studio will automatically assign bin/x86/Debug as your output directory for this project. This is perfectly valid for other project types, except for web applications where ASP.NET expects the assemblies to be output to the Bin folder.

在我的情况下,我发现它们同时被输出到(Bin 和 Bin/x86/Debug),除了一些 dll,莫名其妙地最重要的一个是你的 web 应用程序 dll,丢失了来自 Bin 文件夹.

What I found in my situation was that they were being output to both (Bin and Bin/x86/Debug), with the exception that some of the dll's, and inexplicably the most important one being your web application dll, being missing from the Bin folder.

这显然导致了编译问题,因此出现了无法加载全局类型"异常.清理解决方案和删除程序集对后续构建没有影响.我的解决方案是将 Web 应用程序的项目设置中的输出路径更改为 Bin(而不是 bin/x86/Debug).

This obviously caused a compilation problem and hence the "Could not load type Global" exception. Cleaning the solution and deleting the assemblies made no difference to subsequent builds. My solution was to just change the output path in project settings for the web app to Bin (rather than bin/x86/Debug).

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhefjbha
系列文章
更多 icon
同类精品
更多 icon
继续加载