-
Due to the limited performance of the server, I found that since using Castle + Nhibernate, the server's recompilation process after updating the web site is particularly long, sometimes taking more than 1 minute, even though the published web program is also compiled. The following are the dynamic libraries used by the web:
Castle.Core.dll
Castle.DynamicProxy2.dll
Castle.Facilities.AutomaticTransactionManagement.dll
Castle.Facilities.NHibernateIntegration.dll
Castle.MicroKernel.dll
Castle.Services.Transaction.dll
Castle.Windsor.dll
FredCK.FCKeditorV2.dll
Iesi.Collections.dll
log4net.dll
MySql.Data.dll/System.Data.SQLite.dll
NHibernate.dll
UrlRewritingNet.UrlRewriter.dll
Every time my web project is updated and the web.dll generated after recompiling is uploaded to the server, the server w3p will restart and csc the files in my web directory. The whole process is really long and unbearable.
[I wonder if you guys have any good suggestions]
Later, I thought about whether putting the above dynamic libraries into the GAC would reduce the time required for restarting (practice has proven that there is no obvious change).
This article did not solve the original problem, but because it involves a problem of referencing a third-party dynamic library stored in the GAC in asp.net, I still recorded it (:-) This is the focus of this article).
All the above dynamic libraries are signed, and the process of putting them into GAC is:
1. Register third-party dynamic library into GAC
gacutil -i Castle.Core.dll
gacutil -i Castle.DynamicProxy2.dll
gacutil -i Castle.Facilities.AutomaticTransactionManagement.dll
gacutil -i Castle.Facilities.NHibernateIntegration.dll
gacutil -i Castle.MicroKernel.dll
gacutil -i Castle.Services.Transaction.dll
gacutil -i Castle.Windsor.dll
gacutil -i FredCK.FCKeditorV2.dll
gacutil -i Iesi.Collections.dll
gacutil -i Intelligencia.UrlRewriter.dll
gacutil -i log4net.dll
gacutil -i MySql.Data.dll
gacutil -i NHibernate.dll
gacutil -i System.Data.SQLite.dll
gacutil -i UrlRewritingNet.UrlRewriter.dll
This process is relatively easy, gacutil can be found under the sdk of .net framework (redistribution package)
2. Redefine how web projects reference third-party dynamic libraries: directly reference GAC
Another problem encountered here is that vs2005 cannot reference the third-party dynamic library defined in GAC unless the following settings are made:
Assume that the third-party dynamic library you defined is stored in: c:3rdlibs
Modify the registry: HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkAssemblyFolders
Add an item under this project and point it to c:3rhlibs
Now we can reference third-party GAC libraries in our web projects.
3. Recompile the web and debug:
The first problem: configuration error
view plaincopy to clipboardprint?
Configuration error
Explanation: An error occurred while processing the configuration files required to service this request. Please check the specific error details below and modify the configuration file appropriately.
Parser Error Message: Unable to load file or assembly 'UrlRewritingNet.UrlRewriter' or one of its dependencies. The system cannot find the file specified. (web.config line 50)
Source error:
Line 48:
Line 49: <httpModules>
Line 50: <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
Source file: web.config Lines: 50
Configuration Error Description: An error occurred while processing the configuration files required to service this request. Please check the specific error details below and modify the configuration file appropriately.
Parser Error Message: Unable to load file or assembly 'UrlRewritingNet.UrlRewriter' or one of its dependencies. The system cannot find the file specified. (web.config line 50)
Source error:
Line 48:
Line 49: <httpModules>
Line 50: <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
Source file: web.config Lines: 50
Obviously our web project did not find the library already stored in the GAC. Before being put into GAC, these libraries are compiled and output to the web/bin directory. Now that it cannot be automatically located, we can modify web.config to specify how the library is referenced:
view plaincopy to clipboardprint?
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="log4net" fullName="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
<qualifyAssembly partialName="Castle.Windsor" fullName="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
<qualifyAssembly partialName="Castle.MicroKernel" fullName="Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
... ...
</assemblyBinding>
</runtime>
</configuration>
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="log4net" fullName="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"/>
<qualifyAssembly partialName="Castle.Windsor" fullName="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
<qualifyAssembly partialName="Castle.MicroKernel" fullName="Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
... ...
</assemblyBinding>
</runtime>
</configuration>
Compile, debug and run again
Second error: Compilation error
view plaincopy to clipboardprint?
Server error in '/' application.
-------------------------------------------------- ----------------------------------
Compilation error
Explanation: An error occurred while compiling the resources required to service this request. Please check the following specific error details and modify the source code appropriately.
Compiler error message: CS0012: Type 'Castle.Windsor.IContainerAccessor' is defined in an assembly that is not referenced. A reference to assembly "Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" must be added.
Source error:
[No relevant source lines]
Source file: c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET FilesrootxxxxxxyyyyyyyyApp_Web_default.aspx.zzzzzzz.aaaaaaaa.0.cs Line: 133
Server error in '/' application.
-------------------------------------------------- ----------------------------------
Compilation error description: An error occurred during compilation of the resources required to serve this request. Please check the following specific error details and modify the source code appropriately.
Compiler error message: CS0012: Type 'Castle.Windsor.IContainerAccessor' is defined in an assembly that is not referenced. A reference to assembly "Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" must be added.
Source error:
[No relevant source lines]
Source file: c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET FilesrootxxxxxxyyyyyyyyApp_Web_default.aspx.zzzzzzz.aaaaaaaa.0.cs Line: 133
This time it is a compilation error, but the error message is not clear and the specific content cannot be located for the time being. Modify web.config and add a configuration section (compilation), as follows
view plaincopy to clipboardprint?
<configuration>
<system.web>
... ...
<compilation debug="true" />
... ...
</system.web>
</configuration>
<configuration>
<system.web>
... ...
<compilation debug="true" />
... ...
</system.web>
</configuration>
Debugging again:
view plaincopy to clipboardprint?
Compilation error
Explanation: An error occurred while compiling the resources required to service this request. Please check the following specific error details and modify the source code appropriately.
Compiler error message: CS0012: Type 'Castle.Windsor.IContainerAccessor' is defined in an assembly that is not referenced. A reference to assembly "Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" must be added.
Source error:
Line 134: }
Line 135:
Line 136: protected ASP.global_asax ApplicationInstance {
Line 137: get {
Line 138: return ((ASP.global_asax)(this.Context.ApplicationInstance));
Source file: c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET FilesrootxxxxxxyyyyyyyyApp_Web_default.aspx.zzzzzzz.aaaaaaaa.0.cs Line: 136
Compilation error description: An error occurred during compilation of the resources required to serve this request. Please check the following specific error details and modify the source code appropriately.
Compiler error message: CS0012: Type 'Castle.Windsor.IContainerAccessor' is defined in an assembly that is not referenced. A reference to assembly "Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" must be added.
Source error:
Line 134: }
Line 135:
Line 136: protected ASP.global_asax ApplicationInstance {
Line 137: get {
Line 138: return ((ASP.global_asax)(this.Context.ApplicationInstance));
Source file: c:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET FilesrootxxxxxxyyyyyyyyApp_Web_default.aspx.zzzzzzz.aaaaaaaa.0.cs Line: 136
This error message is the most important:
Compiler error message: CS0012: Type 'Castle.Windsor.IContainerAccessor' is defined in an assembly that is not referenced. A reference to assembly "Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc" must be added.
Obviously, after we modified web.config, the iis service restarted the current web project and compiled it. The first thing to be compiled was global.asax.cs. One of the initialized variables may also be a static one. Variable, Castle.Windsor is called, and csc cannot find this Castle.Windsor, which is really a troublesome process.
First attempt: In the reference section of the web project, set Castle.Windsor. Originally, when the dynamic library was directly referenced, it was output to web/bin synchronously. After the GAC was referenced, this output was canceled. Now reset it. Set to "Copy to local". Of course, the compilation after setting will output this file: Castle.Windsor to web/bin. In this way, the debugging can also pass because he found this dynamic library.
But this does not relieve our doubts, that is, the Assembly defined in <runtime><assemblyBinding>... ...</assemblyBinding><runtime> does not affect the compilation process, so it must be used during the compilation process Which section is it?
Second attempt: Think of the (compilation) section in the first attempt, check the msdn description, and know that there is a definition of <assemblies> in <compilation>. Add the configuration as follows:
view plaincopy to clipboardprint?
<compilation debug="false">
<assemblies>
<add assembly="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
</assemblies>
</compilation>
<compilation debug="false">
<assemblies>
<add assembly="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc"/>
</assemblies>
</compilation>
Then cancel "Copy to local" for Castle.Windsor in the web project, recompile and run.
All are Working Fine.
At this point we have successfully put all the dynamic libraries referenced by third parties into the GAC.