.Net只有几个嵌入式DLL中没有一个没有加载

时间:2017-04-27 11:32:16

标签: .net vb.net dllimport

我使用以下代码加载嵌入式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

只要访问以下嵌入式DLL中的最后三个,程序就会出现JIT错误! 资源代码将DLL复制到文件夹中,如果它不受管理,或者不能像上面所说的那样从byte []加载......我跟踪了以下内容被加载,所有它们在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}

0 个答案:

没有答案