忽略与可执行文件位于同一文件夹中的程序集 .dll
Ignore assembly .dll in same folder as executable
我有一个 .NET 应用程序,如果我将 MySql.Data.dll 程序集与可执行文件放在同一文件夹中,它会崩溃,但如果我移动它,它可以正常工作。同一文件夹中的不同可执行文件依赖于它,因此我需要将其保留在那里。
我该怎么做才能让应用程序忽略这个 dll?
我假设我可以编辑配置文件,但我似乎找不到任何人遇到忽略本地 .dll 的问题,所以我不知道该写什么。
更让我摸不着头脑的是exception details中写的关于loaded assembly的部分。请注意,本地文件夹中的文件(我想忽略的那个)的版本是 6.9.9.0,异常状态是它要加载 6.9.5.0,而加载的文件(来自 GAC)是 6.9.8.0。
这是我的配置文件:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DB" connectionString="*" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
非常感谢您的帮助。
************** Loaded Assemblies **************
---------------------------------------
MySql.Data
Assembly Version: 6.9.8.0
Win32 Version: 6.9.8.0
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/MySql.Data/v4.0_6.9.8.0__c5687fc88969c44d/MySql.Data.dll
----------------------------------------
************** Exception Text **************
System.IO.FileLoadException: Could not load file or assembly
'MySql.Data, Version=6.9.5.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The
located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)
File name: 'MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'
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.Assembly.Load(AssemblyName assemblyRef)
at System.Data.Metadata.Edm.MetadataAssemblyHelper.SafeLoadReferencedAssembly(AssemblyName
assemblyName)
at System.Data.Metadata.Edm.MetadataAssemblyHelper.d__8.MoveNext()
at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetAllDiscoverableAssemblies()
at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetWildcardAssemblies()
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String
assemblyName, String resourceName, ICollection1 uriRegistry,
MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String
path, ExtensionCheck extensionCheck, String validExtension,
ICollection
1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path,
ExtensionCheck extensionCheck, String validExtension, ICollection1
uriRegistry, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths)
at System.Data.Common.Utils.Memoizer
2.<>c__DisplayClass4_0.b__0()
at System.Data.Common.Utils.Memoizer2.Result.GetValue()
at System.Data.Common.Utils.Memoizer
2.Evaluate(TArg arg)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean
initializeAllCollections)
at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
at Panola.Data.Models.PanolaDB..ctor()
at Panola.Data.Services.PanolaConfigurator..ctor(String Name, Boolean UseDefualtRepositories)
at Panola.Data.Services.PanolaConfigurator..ctor(String Name)
at Panola.Tools.Configurator.MainForm.connectToolStripMenuItem_Click(Object
sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e,
ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.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)
这里的问题是程序集绑定;它会尝试多个位置,包括本地文件夹和 GAC。很难压制这一点。然而,我怀疑这里最好的选择是在配置文件中添加一个程序集绑定重定向,告诉 "fusion" 允许 6.9.9.0 代替以前的版本。例如:
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>
我有一个 .NET 应用程序,如果我将 MySql.Data.dll 程序集与可执行文件放在同一文件夹中,它会崩溃,但如果我移动它,它可以正常工作。同一文件夹中的不同可执行文件依赖于它,因此我需要将其保留在那里。
我该怎么做才能让应用程序忽略这个 dll? 我假设我可以编辑配置文件,但我似乎找不到任何人遇到忽略本地 .dll 的问题,所以我不知道该写什么。
更让我摸不着头脑的是exception details中写的关于loaded assembly的部分。请注意,本地文件夹中的文件(我想忽略的那个)的版本是 6.9.9.0,异常状态是它要加载 6.9.5.0,而加载的文件(来自 GAC)是 6.9.8.0。
这是我的配置文件:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DB" connectionString="*" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
非常感谢您的帮助。
************** Loaded Assemblies **************
---------------------------------------
MySql.Data
Assembly Version: 6.9.8.0
Win32 Version: 6.9.8.0
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/MySql.Data/v4.0_6.9.8.0__c5687fc88969c44d/MySql.Data.dll
----------------------------------------
************** Exception Text **************
System.IO.FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' 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.Assembly.Load(AssemblyName assemblyRef) at System.Data.Metadata.Edm.MetadataAssemblyHelper.SafeLoadReferencedAssembly(AssemblyName assemblyName) at System.Data.Metadata.Edm.MetadataAssemblyHelper.d__8.MoveNext() at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetAllDiscoverableAssemblies() at System.Data.Metadata.Edm.DefaultAssemblyResolver.GetWildcardAssemblies() at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection
1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection
1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths) at System.Data.Common.Utils.Memoizer
2.<>c__DisplayClass4_0.b__0() at System.Data.Common.Utils.Memoizer2.Result.GetValue() at System.Data.Common.Utils.Memoizer
2.Evaluate(TArg arg) at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) at Panola.Data.Models.PanolaDB..ctor() at Panola.Data.Services.PanolaConfigurator..ctor(String Name, Boolean UseDefualtRepositories) at Panola.Data.Services.PanolaConfigurator..ctor(String Name) at Panola.Tools.Configurator.MainForm.connectToolStripMenuItem_Click(Object sender, EventArgs e) at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.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)
这里的问题是程序集绑定;它会尝试多个位置,包括本地文件夹和 GAC。很难压制这一点。然而,我怀疑这里最好的选择是在配置文件中添加一个程序集绑定重定向,告诉 "fusion" 允许 6.9.9.0 代替以前的版本。例如:
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>