У меня есть простой исполняемый файл, в котором я хотел бы использовать DLL. Я добавил его в качестве ссылки.Я создал файл app.config, потому что DLL в конечном итоге не будет находиться в каталоге исполняемых файлов.Если я выполняю свою программу из IDE, все в порядке, b / c dll копируется локально, но как только я вытаскиваю свой исполняемый файл, происходит сбой.Мой журнал слияния подразумевает, что он не может найти указанный файл.
Мой метод Main ():
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
Assembly assembly = null;
String dllLocation = @"C:\BMS_ACTD\bin\DX\Tools\BmsReplayAnalysis.dll";
IToolsInterface myProgram = null; //from ToolsInterface.dll
try
{
assembly = Assembly.LoadFrom(dllLocation);
}
catch
{
}
foreach (Type myType in assembly.GetTypes())
{
if (myType.GetInterface(typeof(IToolsInterface).FullName) != null)
{
myProgram = (IToolsInterface)assembly.CreateInstance(myType.Namespace + "." + myType.Name, true);
myProgram.RunTool();
break;
}
}
Вот мой конфигурационный файл:
<runtime>
<dependentAssembly>
<assemblyIdentity name="ToolsInterface" publicKeyToken="null" culture="neutral" />
<codeBase version="1.0.0.0" href="file://C:/BMS_ACTD/bin/DX/Globals/ToolsInterface.dll"/>
</dependentAssembly>
</runtime>
Iне хочу беспокоиться о сильных именах.У меня будет только 1 версия этого dll, и это все, что меня волнует.
Вот выдержка из журнала fusionlog:
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Users\greenj\Desktop\BmsReplayLauncher.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = BMS-JMGREEN\greenj
LOG: DisplayName = ToolsInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/Users/greenj/Desktop/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = BmsReplayLauncher.exe
Calling assembly : BmsReplayLauncher, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\greenj\Desktop\BmsReplayLauncher.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/greenj/Desktop/ToolsInterface.DLL.
LOG: Attempting download of new URL file:///C:/Users/greenj/Desktop/ToolsInterface/ToolsInterface.DLL.
LOG: Attempting download of new URL file:///C:/Users/greenj/Desktop/ToolsInterface.EXE.
LOG: Attempting download of new URL file:///C:/Users/greenj/Desktop/ToolsInterface/ToolsInterface.EXE.
LOG: All probing URLs attempted and failed.