ASP.NET 预编译期间出现类型解析错误

发布于 2024-10-17 14:49:39 字数 1366 浏览 6 评论 0原文

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

[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 类型用 [Serialized] 进行注释。当我们删除 [Serialized] 注释时,aspnet_compiler.exe 会以不同的方式抱怨 - 我们的自定义异常没有这样标记。)

有谁知道为什么抛出自定义异常ASP.NET 预编译期间的异常导致辅助 SerializationException?为什么它试图序列化异常?同样,为什么使用 BCL InvalidOperationException 不会导致次要 SerializationException?

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

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)

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

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日暮斜阳 2024-10-24 14:49:39

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

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

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文