Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:25:09+00:00 2026-06-05T15:25:09+00:00

I have a .dll I’m trying to embed as a resource inside an executable.

  • 0

I have a .dll I’m trying to embed as a resource inside an executable. The following two questions are somewhat helpful, but are not a full help:

Embedding assemblies inside another assembly

This doesn’t seem to work as written; the args.Name cannot be used as written, but even if it’s fixed, the program still complains of a missing .dll, indicating that the assembly is not properly loaded.

Embedding DLLs in a compiled executable

and the link in one of the answers of:

http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/

However, there is no “App.xaml*” file in my project of any sort – I’m not using WPF; I’m using WinForms for my executable (changing isn’t really an option, due to the nature of the executable).

I’m therefore looking for a complete set of instructions for embedding a class library in an executable as a resource and loading that .dll from the resource, without needing a .dll file outside of the embedded resource.

For example, would it be practical to simply add an “App.xaml” file to a WinForms project, or would there be negative interactions I’m not aware of?

Thanks.

Edit: This is what I’m currently using:

/// <summary>
/// Stores the very few things that need to be global.
/// </summary>
static class AssemblyResolver
{
    /// <summary>
    /// Call in the static constructor of the startup class.
    /// </summary>
    public static void Initialize( )
    {
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler( Resolver ) ;
    }


    /// <summary>
    /// Use this to resolve assemblies.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    /// <returns></returns>
    public static Assembly Resolver( object sender, ResolveEventArgs args )
    {
        Assembly executingAssembly = Assembly.GetExecutingAssembly( ) ;
        if ( args.Name == null )
            throw new NullReferenceException(
                "Item name is null and could not be resolved."
            ) ;
        if ( !executingAssembly.GetManifestResourceNames().Contains( 
                "Many_Objects_Display.Resources." +
                new AssemblyName( args.Name ).Name.Replace( ".resources", ".dll" ) )
            )
            throw new ArgumentException( "Resource name does not exist." ) ;

        Stream resourceStream =
            executingAssembly.GetManifestResourceStream(
                "Many_Objects_Display.Resources." +
                new AssemblyName( args.Name ).Name.Replace( ".resources", ".dll" )
            ) ;
        if ( resourceStream == null )
            throw new NullReferenceException( "Resource stream is null." ) ;
        if ( resourceStream.Length >  104857600)
            throw new ArgumentException(
                "Exceedingly long resource - greater than 100 MB. Aborting..."
            ) ;

        byte[] block = new byte[ resourceStream.Length ] ;
        resourceStream.Read( block, 0, block.Length ) ;

        Assembly resourceAssembly = Assembly.Load( block ) ;
        if ( resourceAssembly == null )
            throw new NullReferenceException( "Assembly is a null value." ) ;
        return resourceAssembly ;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:25:10+00:00Added an answer on June 5, 2026 at 3:25 pm

    You need to put the code in your main entry point. Something like this:

    class Program
    {
      static Program()
      {
         AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
      }
    
      static void Main(string[] args)
      {
        // what was here is the same
      }
    
      static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
      {
          // the rest of sample code
      }
    
    }
    

    You can’t just add an App.xaml file to a windows forms application.

    Also that sample code for CurrentDomain_AssemblyResolve is bizarre, I would try this code first. I haven’t tested it but it looks more like the code I’ve used before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DLL library, but I am not familiar with it. How can
I have two DLL files that have the same namespace but they have different
I have a DLL that I can use to pull the following information about
I have a dll with following signature in C++. It is working in c++;
I have a DLL which contains unmanaged classes with methods. I'm trying to call
I have a DLL I need to deploy with my C# application. It's not
I have DLL and PDB files, and source code files. But I can't put
I'm trying to make my library exportable as a DLL but I'm getting a
I have a DLL one.dll that uses a class TwoClass exported from two.dll via
I have a .dll(not my own) that has a delegate. This delegate Callback function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.