我正在創建一個Windows服務,它測試是否可以執行預定作業,然後啓動後臺工作來執行作業。與後臺工作者的Windows服務無法加載文件或程序集錯誤
在windows服務的主線程中,我從位於與windows服務可執行文件相同的目錄中的程序集中創建一個數據訪問層(DAL)對象。 這有效。
從後臺工作者中,我也嘗試創建同一個對象的新實例。看起來這是成功的。 DAL中的方法從程序集加載SQL文件,然後針對給定數據庫執行。
某處在這個過程中,我得到了以下錯誤:
System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Windows\system32\DataConnector.dll' or one of its dependencies. The system cannot find the file specified.
File name: 'file:///C:\Windows\system32\DataConnector.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at DataConnector.DatabaseConnector.UpdateDatabase()
我不知道爲什麼背景工人試圖尋找到了C:\ WINDOWS \ system32 \目錄下。
*在DAL的方法從組件*加載一個SQL文件 - 這是什麼意思? SQL文件是否被編譯到程序集中? – 2014-10-17 09:30:12