load .dll ressource as string
I've got a function which needs to get path to a dll file for running them. To make use of my app easier I don't want to let the user type in path for dll file. I added dll file as ressource already but my methode needs to get the path to the .dll file as string. How to get the string of my dll file called "test2.dll"? All I found was about the use of functions from .dll files in the program itself, but not loading the path to this included .dll.
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
you can try with this
Assembly.GetExecutingAssembly().Location
will give you the patch of executing assembly then:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
here is more information
If I'm understanding you, it sounds like you have a DLL file that is an embedded resource in your project and you want to be able to extract that DLL and then load the resources from that DLL. Here is an example.
First, you need to extract the DLL to a byte array:
byte[] buffer;
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("SomeNamespace.somefile.dll"))
{
buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
}
So now you have this DLL file contained into your buffer
byte array. Next we need to write the byte array out to a file somewhere:
string file = Path.GetTempPath() + "somefile.dll";
File.WriteAllBytes(file, buffer);
Now, finally, you can read in your DLL and extract whatever resource you need to:
var assembly = Assembly.Load(file);
using (var stream = assembly.GetManifestResourceStream("SomeNamespace.someresourcefile.png"))
{
// Read in stream and do something with the resource
}
链接地址: http://www.djcxy.com/p/44492.html
上一篇: 从中央存储库加载DLL的一种方法
下一篇: 将.dll加载为字符串