2014-02-07 66 views
3

母雞我運行Visual Studio 2012中的應用程序,它就像一個魅力,但是當我嘗試運行在bin文件夾中的.exe文件,我得到這個錯誤:Visual Studio中的Borland DLL錯誤

System.IO.FileLoadException: Could not load file or assembly  'Borland.Data.DbxCommonDriver, Version=16.0.0.0, Culture=neutral, PublicKeyToken=a91a7c5705831a4f' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
File name: 'Borland.Data.DbxCommonDriver, Version=16.0.0.0, Culture=neutral, PublicKeyToken=a91a7c5705831a4f' 
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.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) 
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 
at System.Reflection.Assembly.Load(String assemblyString) 
at Borland.Data.TClassRegistryPackageItem..ctor(String PackageName) 
at Borland.Data.TClassRegistry.RegisterPackageClass(String ClassName, String PackageName) 
at Borland.Data.Units.DBXCommon.RegisterClassLoader(TDBXProperties DriverProperties, String ClassNameProp, String ClassNameDefault, String PackageNameProp, String PackageDefault, String& ResultPackageName) 
at Borland.Data.TDBXDriverRegistry.GetDriver(TDBXDriverDef DriverDef) 
at Borland.Data.TDBXConnectionFactory.GetDriver(String DriverName, TDBXProperties DriverProperties) 
at Borland.Data.TDBXConnectionBuilder.CreateConnection() 
at Borland.Data.TDBXConnectionFactory.GetConnection(TDBXContext DBXContext, TDBXProperties ConnectionProperties) 
at Borland.Data.TAdoDbxConnection.Open() 
at ProjectGroep9.LoginForm.connSuccess() in c:\Users\Tom\Project2TI\trunk\ProjectGroep9\ProjectGroep9\LoginForm.cs:line 146 
at ProjectGroep9.LoginForm.bevestigLabel_Click(Object sender, EventArgs e) in c:\Users\Tom\Project2TI\trunk\ProjectGroep9\ProjectGroep9\LoginForm.cs:line 58 
at System.Windows.Forms.Control.OnClick(EventArgs e) 
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
at System.Windows.Forms.Control.WndProc(Message& m) 
at System.Windows.Forms.Label.WndProc(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

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

更新:Visual Studio,當拋出錯誤說: 無法加載程序集Borland.Data.DbxCommonDriver,Version = 16.0.0.0,Culture = neutral,
PublicKeyToken = a91a7c5705831a4f或其依賴項之一。

一個PowerShell命令給了我下面的interbaseAdo.NETDriver Program Files文件夾輸出the.dll:

Borland.Data.DbxCommonDriver, Version=16.0.0.0, Culture=neutral, 
PublicKeyToken=91d62ebb5b0d1b1b 
+0

我和我的同事遇到同樣的問題,請參閱http:// stackoverflow。com/questions/21628601/ado-net-2-0-interbase-driver-and-asp-net-wrong-assembly-reference,你能找出你的系統上的Borland.Data.BdxCommonDriver.DLL的PublicKeyToken是什麼? – RFerwerda

+0

你能否提供更多的細節? 像,所引用的DLL文件仍然在bin文件夾中? – RvdV79

+0

Thanx對於評論傢伙,我今天在學校裏和我的老師一起研究過,他們的反應就像是「這到底是什麼,embarcadero?」 ^^引用的文件位於bin文件夾中:) – Docschnitzel

回答

7

如果您安裝了Embarcadero公司的RAD Studio(我使用Delphi XE2爲例),事實證明他們的dbExpress驅動程序是較新的比那些Embarcadero提供的ADO.NET 2.0驅動程序。

因此,爲了解決您的具體問題,你可能最好Visual Studio解決方案修改app.config文件到這樣的事情:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 

    <system.data> 
    <DbProviderFactories>  
     <remove invariant="Borland.Data.AdoDbxClient" /> 
     <add name="AdoDbx Data Provider" invariant="Borland.Data.AdoDbxClient" 
      description=".Net Framework Data Provider for dbExpress Drivers" 
      type="Borland.Data.TAdoDbxProviderFactory, Borland.Data.AdoDbxClient, 
      Version=16.0.0.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b"/> 
     <remove invariant="Borland.Data.DbxClientDriver" /> 
     <add name="Datasnap AdoDbx Data Provider" invariant="Borland.Data.DbxClientDriver" 
      description=".Net Framework Data Provider for Datasnap" 
      type="Borland.Data.TAdoDbxDatasnapProviderFactory, 
      Borland.Data.DbxClientDriver, Version=16.0.0.0, Culture=neutral, 
      PublicKeyToken=91d62ebb5b0d1b1b"/>  
    </DbProviderFactories> 
    </system.data> 
</configuration> 

這樣做之後,有一個小細節需要被執行。您將不得不找到名爲'dbxdrivers.ini'的dbExpress配置文件的位置,以及'dbxconnections.ini''和。如果將它們放在二進制可執行文件的完全相同的位置,它將起作用。這些驅動程序指向Embarcadero的正確程序集。

還有一個與數據庫建立連接的錯誤,您可以通過以下解決方法修復該錯誤。您可以查找所有提供的dbProviderFactories(即安裝的驅動程序),以確保您的dbExpress驅動程序安裝正確。下面的方法有它內置的(只是快速和骯髒雖然):

public InterbaseTest() 
{ 
    if (null == this.Connection) 
    { 
    try 
    { 
     /* First list all installed and registered DbProviderFactories */ 
     System.Data.DataTable dt = System.Data.Common.DbProviderFactories.GetFactoryClasses(); 
     for (int i = 0; i < dt.Rows.Count; i++) 
     Console.WriteLine("{0}: {1}", i.ToString(), dt.Rows[i][2].ToString()); 

     Console.WriteLine("------------------------------------------------------\n"); 


     this.Connection = new TAdoDbxConnection(
     string.Format("DriverName=Interbase;Database={0};", this.DatabasePath) + 
     "RoleName=RoleName;User_Name=sysdba;"+ 
     "Password=masterkey;SQLDialect=3" +        
     "MetaDataAssemblyLoader=Borland.Data.TDBXInterbaseMetaDataCommandFactory," + 
     "Borland.Data.DbxReadOnlyMetaData,Version=11.0.5000.0,Culture=neutral," + 
     "PublicKeyToken=91d62ebb5b0d1b1b;GetDriverFunc=getSQLDriverINTERBASE;" + 
     "LibraryName=dbxint30.dll;VendorLib=GDS32.DLL" 
     ); 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.Message); 
    } 
    } 
} 

它可能看起來很明顯,this.Connection是類型的DbConnection,這是在這個C#類的字段。

希望它有幫助!

UPDATE

沒有安裝Embarcadero公司的RAD Studio,它可能是你缺乏.ini文件的情況。 內容非常簡單,所以你可以自己創建這些文件。

'dbxconnections.ini'應該包含這樣的:

[IBConnection] 
;DelegateConnection=DBXTraceConnection 
DriverName=Interbase 
Database=database.gdb 
RoleName=RoleName 
User_Name=sysdba 
Password=masterkey 
ServerCharSet= 
SQLDialect=3 
ErrorResourceFile= 
LocaleCode=0000 
BlobSize=-1 
CommitRetain=False 
WaitOnLocks=True 
IsolationLevel=ReadCommitted 
Trim Char=False 

'dbxdrivers.ini'文件(最重要的)的內容應包括:

[Installed Drivers] 
DBXTrace=1 
DBXPool=1 
Interbase=1 
MySQL=1 

[DBXPool] 
DelegateDriver=True 
DriverName=DBXPool 
DriverUnit=Data.DBXPool 
DriverPackageLoader=TDBXPoolDriverLoader,DBXCommonDriver160.bpl 
DriverAssemblyLoader=Borland.Data.TDBXPoolDriverLoader,Borland.Data.DbxCommonDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 

[DBXTrace] 
DelegateDriver=True 
DriverName=DBXTrace 
DriverUnit=Data.DBXTrace 
DriverPackageLoader=TDBXTraceDriverLoader,DBXCommonDriver160.bpl 
DriverAssemblyLoader=Borland.Data.TDBXTraceDriverLoader,Borland.Data.DbxCommonDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 

[AutoCommit] 
False=0 
True=1 

[BlockingMode] 
False=0 
True=1 

[WaitOnLocks] 
False=1 
True=0 

[CommitRetain] 
False=0 
True=1 

[OS Authentication] 
False=0 
True=1 

[Multiple Transaction] 
False=0 
True=1 

[Trim Char] 
False=0 
True=1 

[SQLDialect] 
1=0 
2=1 
3=2 


[Interbase] 
DriverUnit=Data.DBXInterBase 
DriverPackageLoader=TDBXDynalinkDriverLoader,DbxCommonDriver160.bpl 
DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borland.Data.DbxCommonDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 
MetaDataPackageLoader=TDBXInterbaseMetaDataCommandFactory,DbxInterBaseDriver160.bpl 
MetaDataAssemblyLoader=Borland.Data.TDBXInterbaseMetaDataCommandFactory,Borland.Data.DbxInterBaseDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 
GetDriverFunc=getSQLDriverINTERBASE 
LibraryName=dbxint.dll 
LibraryNameOsx=libsqlib.dylib 
VendorLib=GDS32.DLL 
VendorLibWin64=ibclient64.dll 
VendorLibOsx=libgds.dylib 
BlobSize=-1 
CommitRetain=False 
Database=database.gdb 
ErrorResourceFile= 
LocaleCode=0000 
Password=masterkey 
RoleName=RoleName 
ServerCharSet= 
SQLDialect=3 
IsolationLevel=ReadCommitted 
User_Name=sysdba 
WaitOnLocks=True 
Trim Char=False 

[Interbase TransIsolation] 
ReadCommited=1 
RepeatableRead=2 

[MYSQL] 
DriverUnit=Data.DBXMySQL 
DriverPackageLoader=TDBXDynalinkDriverLoader,DbxCommonDriver160.bpl 
DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borland.Data.DbxCommonDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 
MetaDataPackageLoader=TDBXMySqlMetaDataCommandFactory,DbxMySQLDriver160.bpl 
MetaDataAssemblyLoader=Borland.Data.TDBXMySqlMetaDataCommandFactory,Borland.Data.DbxMySQLDriver,Version=16.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b 
GetDriverFunc=getSQLDriverMYSQL 
LibraryName=dbxmys.dll 
LibraryNameOsx=libsqlmys.dylib 
VendorLib=LIBMYSQL.dll 
VendorLibWin64=libmysql.dll 
VendorLibOsx=libmysqlclient.dylib 
BlobSize=-1 
Database=DBNAME 
ErrorResourceFile= 
HostName=ServerName 
LocaleCode=0000 
Password=password 
User_Name=user 
Compressed=False 
Encrypted=False 

如果在您的二進制文件所在的應用程序文件夾中包含這些.ini文件,應該可以使用這些文件。

+0

謝謝你的回答!雖然我沒有RAD工作室(有點貴:D)我會在下個月的幾個月考試後試試這個解決方案! :) – Docschnitzel

+0

沒問題,沒有RAD工作室可能很難找出差異在哪裏,但最好的嘗試仍然包括.ini文件。如果你想念他們,我可以告訴你這些文件的內容(它們很小)。只是放下一張紙條而已。祝你考試順利! – RvdV79

+0

我剛剛更新了我的答案與ini文件的內容。我已經用我自己的二進制文件測試過了,它在你的二進制文件夾中包含這兩個ini文件時起作用。 – RvdV79