“无法加载类型 [Namespace].Global"让我伤心 [英] "Could not load type [Namespace].Global" causing me grief

查看:20
本文介绍了“无法加载类型 [Namespace].Global"让我伤心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .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.

推荐答案

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

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

这篇关于“无法加载类型 [Namespace].Global"让我伤心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆