简体   繁体   English

读取嵌入式Assemby(.dll)时遇到问题

[英]Troubles in reading an embedded assemby (.dll)

So, I'm making a customized installer for a project of mine, and what I needed was to "pack" everything in one file. 因此,我正在为我的一个项目定制安装程序,而我需要的是将所有内容“打包”到一个文件中。 (I couldn't use ILMerge or .NETZ because one of the things I had to include was an unmanaged (was that how it was called?) assembly.) Anyways, I read a lot of stuff mainly from here, and people were saying to do this: (我不能使用ILMerge或.NETZ,因为我必须包括的一件事是未托管的(这是怎么称呼的?)程序集。)无论如何,我主要是从这里读到很多东西,人们在说去做这个:

  • Add the .dll as an Embedded Resource; 将.dll添加为嵌入式资源;
  • Add a handler to the AssemblyResolve method so it fires up when my application can't find the assembly 将处理程序添加到AssemblyResolve方法,以便在我的应用程序找不到程序集时启动
  • In that handler, make it load the .dll from memory using a function that transfers the input stream into a byte array which the Assembly.Load() can use. 在该处理程序中,使用将输入流传输到Assembly.Load()可以使用的字节数组的函数,使其从内存中加载.dll。

I did all that stuff and I added a normal reference to the .dll, so my code can compile properly. 我做了所有这些工作,并添加了对.dll的常规引用,因此我的代码可以正确编译。 However, when I delete the .dll file from the directory where the application is, and try to run it, the "Failed to load file or assembly..." dialog (or whatever it was, you know what I'm talking about) pops up and tells me that it couldn't load my .dll, although I explicitly told it to load it from that byte array in the AssemblyResolve EventHandler. 但是,当我从应用程序所在的目录中删除.dll文件并尝试运行它时,“无法加载文件或程序集...”对话框(或者无论如何,您都知道我在说什么) )弹出窗口并告诉我它无法加载.dll,尽管我明确告诉它要从AssemblyResolve EventHandler中的字节数组加载它。
I'm sorry if this is something which has been answered before. 很抱歉,如果这是以前已经回答过的事情。 Looking at the recommended similar questions, I can't see an answer to this, though. 看推荐的类似问题,我看不到答案。
The only thing I could see that might be related is that "C# would not allow me to load from bytes, unless I'm in a high-security context." 我唯一看到的可能是与之相关的是“除非我处于高安全性上下文中,否则C#将不允许我从字节加载”。 If anyone knows anything, can you please confirm/deny this statement, and tell me what a "high-security context" is? 如果有人知道,您是否可以确认/拒绝此声明,并告诉我什么是“高安全性上下文”? I admit, I'm a noober at complicated stuff. 我承认,我对复杂的事情一无所知。 :) :)

Thanks in advance for your time and answers! 预先感谢您的时间和答复!

Assembly is another name for managed dll - native dll's won't end up in the AssemblyResolve bit afaik. 程序集是托管dll的另一个名称-本机dll不会以AssemblyResolve位afaik结尾。 I don't know if there's any other option but saving the embedded dll to disk at startup, but I haven't found an option to tell the OS (which is responsible for loading unmanaged dll's) how to find the embedded dll. 我不知道是否还有其他选择,只能在启动时将嵌入式dll保存到磁盘,但是我还没有找到告诉操作系统(负责加载非托管dll的方法)如何找到嵌入式dll的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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