Type resolution error during ASP.NET precompilation

天大地大妈咪最大 提交于 2019-12-08 03:04:08

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5020503/type-resolution-error-during-asp-net-precompilation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!