ASP.NET预编译期间的类型解析错误 [英] Type resolution error during ASP.NET precompilation

查看:112
本文介绍了ASP.NET预编译期间的类型解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的.NET 3.5 Web应用程序进行ASP.NET预编译期间,在类型初始值设定项中执行了各种初始化。当环境配置不正确时,类型初始化器之一将引发自定义异常。但是,当引发我们的自定义异常时,aspnet_compiler.exe会告诉我们以下内容:

During ASP.NET precompilation of our .NET 3.5 web application, various initialization is performed in type initializers. One of the type initializers throws a custom exception when the environment is incorrectly configured. However, when our custom exception is thrown, here is what the aspnet_compiler.exe tells us:

[exec] error ASPRUNTIME: Type is not resolved for member 'App.Project.CustomException,App.Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
[exec]
[exec] [SerializationException]: Type is not resolved for member 'App.Project.CustomException,App.Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
[exec]    at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback)
[exec]    at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback, Boolean forceCleanBuild)
[exec]    at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback)
[exec]    at System.Web.Compilation.Precompiler.Main(String[] args)

请注意,其中不包含真实堆栈跟踪信息。但是,当我更改代码以引发InvalidOperationException(而不是自定义异常)时,堆栈跟踪将正确包含在内。 (顺便说一句,我们的CustomException类型带有[Serializable]注释。当我们删除[Serializable]注释时,aspnet_compiler.exe会有所不同,即我们的自定义异常未标记为此类。)

Notice that no "real" stack trace information is included. However, when I change our code to throw an InvalidOperationException (instead of our custom exception), the stack trace is included correctly. (As an aside, our CustomException type is annotated with [Serializable]. When we remove the [Serializable] annotation, the aspnet_compiler.exe complains differently -- that our custom exception is not marked as such.)

有人知道为什么在ASP.NET预编译期间引发自定义异常会导致辅助SerializationException吗?为什么要尝试序列化异常?同样,为什么使用BCL InvalidOperationException not 不会导致次要SerializationException?

Does anyone know why throwing a custom exception during ASP.NET precompilation is causing the secondary SerializationException? Why is it trying to serialize the exception? Similarly, why does using a BCL InvalidOperationException not cause the secondary SerializationException?

这可能是因为aspnet_compiler.exe试图执行某种排序对意外异常的反思? (因此,由于没有加载App.Project程序集,因此无法解析类型?)

Could this be because the aspnet_compiler.exe is trying to do some sort of reflection on unexpected exceptions? (And therefore since it does not have our App.Project assembly loaded, it is unable to resolve the type?)

推荐答案

它似乎aspnet_compiler.exe程序使用.NET Remoting与ASP.NET运行时进行通信。当ASP.NET运行时引发我的自定义异常时,aspnet_compiler.exe无法反序列化它,因为它无法解析该自定义异常的类型,因为我的App.Project程序集不在GAC中,也无法通过对aspnet_compiler.exe的路径搜索获得

It appears that the aspnet_compiler.exe program uses .NET Remoting to communicate with the ASP.NET runtime. When the ASP.NET runtime throws my custom exception, the aspnet_compiler.exe is unable to deserialize it because it cannot resolve the type of the custom exception because my App.Project assembly is not in the GAC nor available via path search to aspnet_compiler.exe.

为了测试这个假设,我将App.Project程序集复制到与aspnet_compiler.exe(C:\WINDOWS\Microsoft.NET\Framework \v2.0.50727)并执行了预编译。抛出自定义异常时,它将带有我期望的正常堆栈跟踪,并且不会发生SerializationException。

To test this hypothesis, I copied the App.Project assembly into the same directory as aspnet_compiler.exe (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727) and performed the precompilation. When the custom exception is thrown, it comes out with the normal stack trace I would expect and the SerializationException does not occur.

这篇关于ASP.NET预编译期间的类型解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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