Download assembly from embedded resource

I would like to download the DLL file (Test.dll) as an assembly. I can do this using both Visual Studio direct links (e.g. loading the dll as a link to my C # application) and loading the dll using the method Assembly.LoadFile(filename). Now I would like to add my DLL file as an embedded resource to the Visual Studio application and load the DLL file as an assembly. I know how to load this resource as a byte array, is there some correlation between the byte array and the assembly that I could use? In addition, I need to be able to call a method located in a DLL file. See the code below - this will once again explain what I'm doing.

Assembly SampleAssembly = Assembly.LoadFrom("WindowsFormsApplication2.ThisisaTESTDLL.dll");
Type myType = SampleAssembly.GetTypes()[0];
MethodInfo Method = myType.GetMethod("myVoid");
object myInstance = Activator.CreateInstance(myType,null);
Method.Invoke(myInstance,new object[] { "param1", "param1"});

If I am missing something here, please let me know and I will edit the original post.

+5
source share
2 answers

Assembly.GetExecutingAssembly (). GetManifestResourceStream (...)

That should give you a Stream object. You can read an array of bytes from this.

You can load this with Assembly.Load

+5
source

AxInterop.WMPLib.dll Interop.WMPLib.dll exe . void Main() Program.cs. .NET 3.5 . DLL exe . . "res" - "res.resx", DLL.

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(    
(s, a) =>
{
    if (a.Name.Substring(0, a.Name.IndexOf(",")) == "AxInterop.WMPLib")
    {
        return Assembly.Load(res.AxInterop_WMPLib);
    }

    if (a.Name.Substring(0, a.Name.IndexOf(",")) == "Interop.WMPLib")
    {
        return Assembly.Load(res.Interop_WMPLib);
    }

    return null;
}   

);

+1

All Articles