一、昨天晚上擺弄Dotnetnuke到四點,最后在裝一個SkinTuner的皮膚(調試)控制器時,出現嚴重錯誤導致無法瀏覽管理網站:
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
二、為了查看詳細錯誤,用ftp工具將web.config下載下來修改 <customErrors mode="RemoteOnly" />為 <customErrors mode="Off" />顯示如下詳細錯誤:
Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)
Stack Trace:
[FileLoadException: Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
[FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
[ConfigurationErrorsException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591
[HttpException (0x80004005): Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
三、可以看出,根本原因是 Could not load file or assembly 'System.Data.SQLite,可以斷定,最后安裝的SkinTuner使用的SQLite,查看安裝色發現果然有System.Data.SQLite.dll,在網站里也找到了System.Data.SQLite.dll,但卻無法加載,為什么呢?搜索ould not load file or assembly 'System.Data.SQLite找到答案,我正好用的godaddy.com的空間,這一錯誤是godaddy的限制造成的!:

System.Data.SQLite.dll是無法在godaddy的服務器上使用的。原因是godaddy的ASP.NET2.0及以上的IIS使用了“信任級別”的限制:TrustLevel=”Medium”,也就是說,很多第三方的dll將無定法在這個級別下運行。必須把TrustLevel設置為”Full”,才可以使用。但是出於安全考慮godaddy一般不會開發這個信任級別。
為什么TrustLevel=”Medium”,就無法使用System.Data.SQLite.dll,是因為當服務器設置了TrustLevel=”Medium”之后,要求運行的dll必須是“完全托管代碼”(pure managed code),並且不能包含任何的 P/Invoke調用或使用任何的原始API(raw API)調用。不幸的是,System.Data.SQLite.dll使用了P/Invoke調用。所以無法跑在TrustLevel=”Medium”級別下。
如果一定要使用SQLite數據庫的話,方法是有的:
1、使用ASP.NET1.1(當然這樣就沒法使用很多東西,包括EF層面上的)
2、使用“托管代碼”(managed code)的Sqlite數據庫,這里有一個可以使用:http://code.google.com/p/managed-sqlite/
為什么TrustLevel=”Medium”,就無法使用System.Data.SQLite.dll,是因為當服務器設置了TrustLevel=”Medium”之后,要求運行的dll必須是“完全托管代碼”(pure managed code),並且不能包含任何的 P/Invoke調用或使用任何的原始API(raw API)調用。不幸的是,System.Data.SQLite.dll使用了P/Invoke調用。所以無法跑在TrustLevel=”Medium”級別下。
如果一定要使用SQLite數據庫的話,方法是有的:
1、使用ASP.NET1.1(當然這樣就沒法使用很多東西,包括EF層面上的)
2、使用“托管代碼”(managed code)的Sqlite數據庫,這里有一個可以使用:http://code.google.com/p/managed-sqlite/
四、下載http://managed-sqlite.googlecode.com/svn/branches/bin/1.0.0.1340/ManagedSQLite.zip后改名為System.Data.SQLite.dll,上傳到網站bin目錄下
結果出現如下錯誤:
Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Data.SQLite' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Stack Trace:
[FileLoadException: Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
[ConfigurationErrorsException: Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +618
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +209
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +94
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +332
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +591
[HttpException (0x80004005): Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8946484
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
五、The located assembly's manifest definition does not match the assembly reference 原來是版本不匹配造成的,版本設置或檢查是在哪里進行的呢,是SkinTuner里的文件設置的(搜索了所有安裝文件沒找到)還是由dnn系統檢查的(若是,在哪里我也不清楚,網上沒搜到)。
於是我有個想法:先想辦法使網站恢復正常-卸載SkinTuner-將SkinTuner.zip里的System.Data.SQLite.dll替換成純托管代碼版的-再安裝,看看能不能自動識別版本以注冊。(有這些想法都是由於對具體注冊機制不了解),結果還是和上面的錯誤一樣,同校的方法,不過這次替換成官方最新版SQLite,這次沒有出錯(難道最新版已經使用完全托管的代碼了?),但是在頁面上添加該模塊后,在模塊里提示了版本不匹配的錯誤,難道要暴力修改SQLite不成,算了懶得弄了,
SkinTuner倒底有多大用處都不清楚,
干脆卸載了SkinTuner。
雖然沒有能成功運行SkinTuner,但起碼在實踐中解決了這種情況下網站無法訪問的問題,也許安裝其它擴展出現此類問題時可如法炮制。