Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

possible to embed dll inside c# app

This topic is 4860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
It is probably technically possible, but only with some extremely advanced and arcane trickery. In the end, it would amount to compacting the two files and extracting the DLL into a temporary file before it was loaded. DLLs are Dynamically Linked Libraries. They are designed to be separate from the main program code and loaded separately, so that multiple programs can share them, and only have to load them when needed.

What are you wanting to use such a combined file for? Perhaps there is an alternative solution?

Share this post


Link to post
Share on other sites
The reason is because I am shipping my c# app with a dll I wrote (both in the same directory). While this works fine on my computer and many other computers, my app cannot find the dll on other computers. It appears that about half of computers can find the dll and half can't. I just figured that if it can't even find the dll when it is the same local directory, it would be forced to find it when its embedded but this won't seem to work.

Share this post


Link to post
Share on other sites
Quote:
Original post by NoahAdler
If the .dll is a .NET assembly, you can certainly embed it as a resource, and then load it using Assembly.Load(byte[]), which just loads an assembly from a raw COFF image.

-bodisiw


This sounds like exactly what I want to do. I am not sure what to pass to the Assembly.Load method though.

Share this post


Link to post
Share on other sites
A quick example:


class CoffLoader {
private static void OnAssemblyLoad(object o, AssemblyLoadEventArgs args) {
Console.WriteLine("Loaded assembly {0}", args.LoadedAssembly);
}

public static void Main() {
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CoffAssembly.dll");
byte[] coffImage = new byte[stream.Length];
stream.Read(coffImage, 0, coffImage.Length);

AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(OnAssemblyLoad);
Assembly coffAssembly = Assembly.Load(coffImage);
}
}




Just make sure you embed the assembly (called CoffAssembly.dll in the example above) as a resource when you compile, in addition to referencing it.

Hope this helps.

-bodisiw

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!