C# Global.asax 小改动后解析错误并恢复到以前的版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16621069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:29:40  来源:igfitidea点击:

Global.asax parse error after minor change and revert to previous version

c#asp.net.netglobal-asaxparse-error

提问by Raheel Khan

The project in context is:

上下文中的项目是:

  • ASP .NET Web Application
  • .NET Framework: 4
  • Platform Target: x86
  • IDE: Visual Studio 2010 Ultimate SP1
  • Multiple projects in solution with ASP .NET being the startup project.
  • ASP .NET Web 应用程序
  • .NET 框架:4
  • 平台目标:x86
  • IDE:Visual Studio 2010 Ultimate SP1
  • 解决方案中的多个项目,以 ASP .NET 作为启动项目。

It has been in production for months without glitches until yesterday. I cleaned up the [Global.asax]file (removed unused using statements, refactored, etc.), ran the solution and got the following error:

直到昨天,它已经投入生产数月而没有出现故障。我清理了[Global.asax]文件(删除了未使用的 using 语句、重构等),运行解决方案并得到以下错误:

Description:An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message:Could not load type 'CloudTech.ATS.WebClient.Global'.
Source File:/global.asax Line:1
Source Error:Line 1: <%@ Application CodeBehind="Global.asax.cs" Inherits="CloudTech.ATS.WebClient.Global" Language="C#" %>

说明:解析服务此请求所需的资源期间发生错误。请查看以下特定解析错误详细信息并适当修改您的源文件。
解析器错误消息:无法加载类型“CloudTech.ATS.WebClient.Global”。
源文件:/global.asax 行:1
源错误:第 1 行: <%@ Application CodeBehind="Global.asax.cs" Inherits="CloudTech.ATS.WebClient.Global" Language="C#" %>

Error snapshot

错误快照

Here is the Global.asax Markup:

这是Global.asax 标记:

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

Here is the Global.asax.cs Code(with internal code removed):

这是Global.asax.cs 代码(删除了内部代码):

using System;
using System.Linq;

namespace CloudTech.ATS.WebClient
{
    public class Global: System.Web.HttpApplication
    {
    }
}

After wrestling with this error for a while, I searched, restarted my computer, performed a full clean on the solution, force rebuilt but with no avail. Frustrated, I finally changed only the web application target to "Any CPU" and it worked. Unfortunately, "Any CPU" is not an option or a solution to the issue at hand. Changing it back to "x86" brings the same error back. This happened once and since then, no combination of target platform or debug/release configuration works anymore (same error).

在与此错误搏斗了一段时间后,我进行了搜索,重新启动了计算机,对解决方案进行了全面清理,强制重建但无济于事。令人沮丧的是,我最终只将 Web 应用程序目标更改为“任何 CPU”并且它起作用了。不幸的是,“任何 CPU”都不是解决手头问题的选项或解决方案。将其改回“x86”会带来相同的错误。这发生过一次,从那以后,目标平台或调试/发布配置的组合不再起作用(相同的错误)。

Furthermore:

此外:

  • My development machines are all x64.
  • Checked in the solution, had multiple colleagues test on their machines (both x86 and x64) with the same result.
  • Restored the entire project to a clean state from 3 days ago and the error still persists!
  • Verified tat absolutely NO changes were made to the Web.config files, or any other files in the solution for that matter.
  • 我的开发机器都是x64的。
  • 检查解决方案,让多个同事在他们的机器(x86 和 x64)上测试,结果相同。
  • 从3天前将整个项目恢复到干净状态,错误仍然存​​在!
  • 已验证 tat 绝对没有对 Web.config 文件或解决方案中的任何其他文件进行任何更改。

Lastly, the only change to my development systems has been windows updates (regular security updates) and I have tried the solution on systems without updates with the same results.

最后,对我的开发系统的唯一更改是 Windows 更新(常规安全更新),我在没有更新的系统上尝试了该解决方案,结果相同。

Any help would be appreciated.

任何帮助,将不胜感激。

采纳答案by Sain Pradeep

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

清理解决方案和删除程序集对后续构建没有影响。我的解决方案是将 Web 应用程序的项目设置中的输出路径更改为 Bin(而不是 bin/x86/Debug)。

Source:- "Could not load type [Namespace].Global" causing me grief

来源:- “无法加载类型 [Namespace].Global”让我感到悲伤

回答by AceMark

we had a similar issue here.

我们在这里遇到了类似的问题。

and what we did was just to close the IDE. and open it again, and then build, then run.

我们所做的只是关闭IDE。并再次打开它,然后构建,然后运行。

pretty frustrating and confusing.

非常令人沮丧和困惑。

回答by GoAntonio

  • using Notepad, edit your Global.asax file to make sure it inherits from your web app's namespace
  • check the project properties for its assembly name and default namespace
  • delete your old assemblies from the bin directory (old project assemblies can cause problems!)

    good luck!

  • 使用记事本,编辑您的 Global.asax 文件以确保它继承自您的网络应用程序的命名空间
  • 检查其程序集名称和默认命名空间的项目属性
  • 从 bin 目录中删除旧程序集(旧项目程序集可能会导致问题!)

    祝你好运!

回答by ivamax9

Regular ASP.NET Web Application has 2 files in solution folder:

常规 ASP.NET Web 应用程序在解决方案文件夹中有 2 个文件:

  1. Global.asax
  2. Global.asax.cs
  1. 全球.asax
  2. Global.asax.cs

Make sure that class in Global.asax.cs:

确保 Global.asax.cs 中的类:

namespace YourWebAppNamespace
{
  public class MvcApplication : HttpApplication
  {
     ...

Has the same/right name in Global.asax:

在 Global.asax 中具有相同/正确的名称:

<%@ Application Codebehind="Global.asax.cs" Inherits="YourWebAppNamespace.MvcApplication" Language="C#" %>

I got an issue with this when I manually changed class name in Global.asax.csfile, so as for result I had the same error as you and from my perspective, it should be more informative. I know that this question already was answered, but maybe my case can be helpful for someone.

当我手动更改Global.asax.cs文件中的类名时,我遇到了这个问题,因此结果我和你有同样的错误,从我的角度来看,它应该提供更多信息。我知道这个问题已经得到了回答,但也许我的情况可能对某人有所帮助。