.Net только 1 из нескольких встроенных DLL не загружается
Я использую следующий код для загрузки встроенного ресурса DLL (сокращенный код для краткости):
Dim ba() As Byte = Nothing
Dim asm As System.Reflection.Assembly = Nothing
Dim curAsm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Using stm As Stream = curAsm.GetManifestResourceStream(embeddedResource)
ba = New Byte(CInt(stm.Length) - 1) {}
stm.Read(ba, 0, CInt(stm.Length))
Try
asm = System.Reflection.Assembly.Load(ba)
dic.Add(asm.FullName, asm)
If verbose Then MsgBox("Loaded direct from embedded resources OK: " & fileName)
Return
Catch e As Exception
If verbose Then MsgBox(fileName & " - Error: " & e.Message)
' Purposely do nothing
' Unmanaged dll or assembly cannot be loaded directly from byte[]
' Let the process fall through for next part
End Try
End Using
Программа JIT выдает ошибки каждый раз при обращении к последним ТРИ из следующих встроенных DLL! Код ресурса копирует DLL в папку, если она неуправляема или не может быть загружена из байта [], как сказано выше... Я проследил загрузку следующего, ВСЕ из них регистрируются в System.Reflection.Assembly.Load - не нужно копировать в папку для загрузки обычным способом.
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.ConnectionInfo.dll", "Microsoft.SqlServer.ConnectionInfo.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.Dmf.dll", "Microsoft.SqlServer.Dmf.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.Management.Sdk.Sfc.dll", "Microsoft.SqlServer.Management.Sdk.Sfc.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.Smo.dll", "Microsoft.SqlServer.Smo.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.SmoExtended.dll", "Microsoft.SqlServer.SmoExtended.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.SqlServer.SqlEnum.dll", "Microsoft.SqlServer.SqlEnum.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.WindowsAPICodePack.dll", "Microsoft.WindowsAPICodePack.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Microsoft.WindowsAPICodePack.Shell.dll", "Microsoft.WindowsAPICodePack.Shell.dll")
EmbeddedAssembly.preLoad("DatabaseRestore.Ionic.Zip.Reduced.dll", "Ionic.Zip.Reduced.dll")
Несмотря на это, 3 DLL: Zip.Reduce, а также WindowsAPICodePack и WindowsAPICodePack.Shell вызывают следующую ошибку JIT...
Я не понимаю, ПОЧЕМУ эти последние три DLL сообщаются как отсутствующие при запуске программы, когда они были успешно загружены? Ошибка JIT дает точную версию DLL, которую я встроил!
Я не знаю, что пытаться диагностировать проблему.
(К счастью, программа работает с этими 3 DLL только в папке программы, но я хочу понять, почему я не могу их встраивать.)
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at DatabaseRestore.RestoreEngine.restore(RestoreInformation restoreDetails)
at DatabaseRestore.FileBrowser.button_restore_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.6.1086.0 built by: NETFXREL4STAGE
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
DatabaseRestore
Assembly Version: 1.0.9.6
Win32 Version: 1.0.9.6
CodeBase: file:///C:/ProgramOther/DatabaseRestore/DatabaseRestore.exe
----------------------------------------
....More....
----------------------------------------
Microsoft.SqlServer.SmoExtended
Assembly Version: 10.0.0.0
Win32 Version: 10.50.6000.34 ((KJ_SP3).140819-1214 )
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.SqlServer.SmoExtended/10.0.0.0__89845dcd8080cc91/Microsoft.SqlServer.SmoExtended.dll
----------------------------------------
Microsoft.SqlServer.SqlEnum
Assembly Version: 10.0.0.0
Win32 Version: 10.50.6000.34 ((KJ_SP3).140819-1214 )
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Microsoft.SqlServer.SqlEnum/10.0.0.0__89845dcd8080cc91/Microsoft.SqlServer.SqlEnum.dll
----------------------------------------
Microsoft.WindowsAPICodePack
Assembly Version: 1.1.0.0
Win32 Version: 1.0.9.6
CodeBase: file:///C:/ProgramOther/DatabaseRestore/DatabaseRestore.exe
----------------------------------------
Microsoft.WindowsAPICodePack.Shell
Assembly Version: 1.1.0.0
Win32 Version: 1.0.9.6
CodeBase: file:///C:/ProgramOther/DatabaseRestore/DatabaseRestore.exe
----------------------------------------
Ionic.Zip.Reduced
Assembly Version: 1.9.1.8
Win32 Version: 1.0.9.6
CodeBase: file:///C:/ProgramOther/DatabaseRestore/DatabaseRestore.exe
----------------------------------------
Microsoft.GeneratedCode
Assembly Version: 1.0.0.0
Win32 Version: 4.6.1064.2 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
{Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
CodeBase: "file:///C:/AssetManager/Tools/DatabaseRestore/DatabaseRestore_VisualStudio/DatabaseRestore/bin/Debug/DatabaseRestore.exe"
CustomAttributes: Count = 17
DefinedTypes: {Length=100}
EntryPoint: Nothing
EscapedCodeBase: "file:///C:/AssetManager/Tools/DatabaseRestore/DatabaseRestore_VisualStudio/DatabaseRestore/bin/Debug/DatabaseRestore.exe"
Evidence: {System.Security.Policy.Evidence}
ExportedTypes: {Length=51}
FullName: "Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
GlobalAssemblyCache: False
HostContext: 0
ImageRuntimeVersion: "v2.0.50727"
IsDynamic: False
IsFullyTrusted: True
Location: ""
ManifestModule: {Microsoft.WindowsAPICodePack.dll}
Modules: {Length=1}
PermissionSet:
ReflectionOnly: False
SecurityRuleSet: Level1 {1}