简体   繁体   中英

Ignore assembly .dll in same folder as executable

I have a .NET application that crashes if I have the MySql.Data.dll assembly in the same folder as the executable but works fine if I move it. A different executable in the same folder is dependent on it so I need to keep it there.

What can I do to make the app ignore this dll? I assume I can edit the config file but I can't seem to find anyone having had the problem of ignoring a local .dll, so I don't know what to write.

What makes me even more confused is the part about loaded assemblies written in the details of the exception. Mind you the file in the local folder (the one I want to ignore) is versioned 6.9.9.0 and the exception states that it wants to load 6.9.5.0 where as the loaded one (from the GAC) is 6.9.8.0.

This is my configuration file:

<?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>

Very thankful for any help.

************** 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.Loa d(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, ICollection 1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths) at System.Data.Common.Utils.Memoizer 1 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.Memoizer 2.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) a t 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)

The problem here is assembly binding; it tries multiple locations, including the local folder and GAC. It is very hard to suppress this. I suspect, however, that the best option here is to add an assembly-binding redirect in the config file, to tell "fusion" to allow 6.9.9.0 in place of previous versions. For example:

  <dependentAssembly>
    <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" />
    <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
  </dependentAssembly>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM