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

  • SEARCH
  • Home
  • 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 3600568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:30:43+00:00 2026-05-18T20:30:43+00:00

I have a C# application (project A) that requires X.dll. I have added the

  • 0

I have a C# application (project A) that requires X.dll. I have added the project that produces X.dll to A as a reference in visual studio. I have also added the release build of X.dll to a resource file in A as a binary. I have told project A not to copy X.dll to the output directory.

Now I want A.exe to load, say “hey I can’t find this file”, then look in the resource file and use Assembly.Load(byte[]) get X.dll back. I have the code that re-magicifies the DLL back, however this code never get called.

Currently I have a bone simple project, just trying to get it to work. It compile OK. When I run it, I get a FileNotFoundException on X.dll.

I have:

[STAThread]
static void Main()
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}

But the breakpoint in *CurrentDomain_AssemblyResolve* never gets hit. I get a FileNotFoundException immediately. Surely there is something I a missing?

  • 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-05-18T20:30:43+00:00Added an answer on May 18, 2026 at 8:30 pm

    This question seems to be very similar to what you are trying to achieve, and it worked for the asker.

    Merge .dll into C# Assembly?

    Are you doing something differently? Specifically, if you’re targetting an older version of the .NET Framework, maybe that’s a hint for understanding why your application is behaving differently.

    Another direction, use a tool such as Fusion Log Viewer to analyze what was going on when you tried to load the assembly. This may give some more hints. If you manage to get log information, posting it in the question may help someone figure it out.

    EDIT: Another explanation, following your comment.

    Well, now I think I know what the problem is.

    In your Main method, you are refering to the type in the other dll. But you are doing it in static code, i.e. you use the type explicitly in the code (as opposed to loading it dynamically by its name).

    Why is this a problem? The CLR tries to load your assembly in order to JIT Main itself.

    Your FileNotFoundException was thrown while Main was being compiled. Main didn’t even start running, and therefore your event handler wasn’t registered.

    A simple way to check if I’m right is to change the code to something like this:

    static public void Main(string[] args)
    {
        AppDomain.CurrentDomain.AssemblyResolve += MyEventHandler;
        MyMain();
    }
    
    // The CLR will actually try to load your assembly before even starting the execution
    // of this method. It needs the assembly in order to JIT the method because it has to 
    // know the Thing type.
    static public void MyMain()
    {
        using(var thing = new Thing())
        {
             // ...
        }
    }
    

    The important difference is that Main has no dependency on another assembly, so there will be no problem to JIT and run it.

    By the time MyMain is being JIT’ed, your event handler is already in place so you can manually load the assembly.

    By the way, to avoid another possible similar pitfall, make sure that the class in which Main is defined doesn’t have any field with a type from the other assembly, because in this case also, the CLR will try loading the assembly before Main starts, in order to compile it.

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

Sidebar

Related Questions

I have a C# application (project A) that requires X.dll. I have added the
I have a project I'm working on that requires our WPF application read SMS
I have a C# GUI application that references a Managed C++ project, which requires
I have a web application project that works with a quite large database (over
I have a web application project (wap) that is successfully being deployed to a
I am starting a web application project that will have an Adobe Flex front-end
I have a custom HttpModule rewrite engine in an existing web application project that
I have a console application project in C# 2.0 that needs to write something
I have a large project that runs on an application server. It does pipelined
I have gwt-project that is comunication to database. Application design mvp pattern and view

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.