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 8099143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:18:26+00:00 2026-06-05T22:18:26+00:00

I have a general purpose Utility dll file used in my WPF program. The

  • 0

I have a general purpose Utility dll file used in my WPF program. The first thing my program does is check for an updated dll file and copies it to the executing directory – all without referencing any methods or properties from the dll.

When I compile and run the program from inside Visual Studio (v10) everything works as expected. The program starts, checks the dll file, copies if needed and then proceeds to use the assembly.

If I run the compiled .exe file from Windows Explorer it seems the first thing it does is load the Util.dll assembly. This locks the file and will not allow me to update it.

Does anyone have some insight on why the program would opperate differently in Visual Studio vs the .exe file? Any thoughts on tracing what is causing the assembly to load when running the .exe file?

Here is a code snippet of the program startup:

void AppLoad(object sender, StartupEventArgs e)
{

  //Used to see what assemblies are loaded.
  System.Text.StringBuilder sb = new System.Text.StringBuilder();
  foreach (var item in AppDomain.CurrentDomain.GetAssemblies())
  {
    sb.AppendLine(item.FullName.ToString());
  }
  System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "test.txt", sb.ToString());


  //Check for the latest Util dll.
  if (!UpdateUtil())
  {
    //Shutdown.
    Application.Current.Shutdown();
    return;
  }

  //Start the main window.
  MainWindow m = new MainWindow();
  m.Show();
}

bool UpdateUtil()
{
  //Verify network path.
  if (!Directory.Exists(_componentPath))
  {
    MessageBox.Show("The program encountered an error.\r\rPlease contact your Program Administrator with the following information:\r\r" +
      "Program Name - Genesis Admin\r\r" +
      "Error Message - Network Component path not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
    return false;
  }
  //Verify file existance.
  string sourceFileName = _componentPath + "Util.dll";
  if (!File.Exists(sourceFileName))
  {
    MessageBox.Show("The program encountered an error.\r\rPlease contact your Program Administrator with the following information:\r\r" +
      "Program Name - Genesis Admin\r\r" +
      "Error Message - Network Util file not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
    return false;
  }

  string destFileName = AppDomain.CurrentDomain.BaseDirectory + "Util.dll";
  if (!File.Exists(destFileName) || File.GetLastWriteTime(sourceFileName) > File.GetLastWriteTime(destFileName))
    File.Copy(sourceFileName, destFileName, true);

  return true;
}
  • 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-05T22:18:29+00:00Added an answer on June 5, 2026 at 10:18 pm

    This is in general a risky thing to do, assemblies get loaded by the just-in-time compiler when it needs to generate the machine code for a method. What you are probably not counting on is code that gets inlined, an important optimization that’s enabled in the release build. That optimization is off when you run with the debugger.

    It isn’t obvious in your snippet which type might be loaded from “util.dll”. But be sure to restructure your code so that all types that are from util.dll are in separate methods far removed from UpdateUtil() call. Suppress inlining with the [MethodImpl(MethodImplOptions.NoInlining)] attribute on the method.

    By far the best way to do it is with a little bootstrapper .exe file that does the test and then starts your main .exe. But do keep in mind that you’ll no doubt hit the wall again when you run this code on the user’s machine, you can’t copy DLLs into c:\program files without UAC elevation. This is really an installer task, it shouldn’t be in your code.

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

Sidebar

Related Questions

Does a free general purpose ASN.1 Decode/Dump/Inspect program exist? I have a suspect ASN.1
I have a general purpose file storage backed by Google App Engine Blobstore, when
To have a general-purpose documentation system that can extract inline documentation of multiple languages,
I have developed several general purpose script functions, for Google Spreadsheet apps. Currently I
I have a facebook app that I authenticate using a general-purpose authentification. Like this:
I have a general question about the new Django 1.3 static file framework. I
I'm creating a general purpose web service that is likely to have a number
So I have this general purpose HashTable class I'm developing, and I want to
I am working on a program which includes a general purpose engine, some program
I am after a general purpose unspecialised plain text file extractor. Firstly before people

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.