Unusual behavior in Release build
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Unusual behavior in Release build

  1. #1
    Join Date
    Mar 2005
    Posts
    1

    Unusual behavior in Release build

    I am creating a windows forms application using C# and VS 2010. The application implements DirectoryServices to modify the Metabase on Windows 2003 Servers running IIS 6. When I am building the applicaiton and running in Debug mode (i.e. Solution Configuration = Debug), my code executes and performs as expected.

    Here is a block of code that creates a new application pool on the specified web server:

    01.public static void CreateAppPool(string MetabasePath, string AppPoolName)
    02.{
    03. try
    04. {
    05. if (MetabasePath.EndsWith("/W3SVC/AppPools"))
    06. {
    07. using (DirectoryEntry appPools = new DirectoryEntry(MetabasePath))
    08. {
    09. using (DirectoryEntry newPool = appPools.Children.Add(AppPoolName, "IIsApplicationPool"))
    10. {
    11. appPools.CommitChanges();
    12. }
    13. }
    14. }
    15. else
    16. {
    17. throw new Exception("Application pools can only be created in the */W3SVC/AppPools node.\r\n");
    18. }
    19. }
    20. catch (Exception ex)
    21. {
    22. throw new Exception("Unable to create application pool.", ex);
    23. }
    24.}

    The code is fairly straight forward. When I run the app in Debug and select a server and app pool name, the metabase is updated properly and I can verify the new pool has been added to the server. However, when I run in "Release" mode, the application appears to execute the block of code above correctly (no errors are thrown or unhandled) but the new app pool is not created. There is no evidence that the app pool exists in the Metabase or the IIS MMC.

    The line that appears to be the issue is this:

    using (DirectoryEntry newPool = appPools.Children.Add(AppPoolName, "IIsApplicationPool"))

    The appPools.Children.Add executes without error but will not behave correctly in Release mode. In Release mode, the Children collection does not update. All other code executes and behaves correcrtly (ex. My RemoveAppPool method works correctly in Debug and Release). this one has me really stumped.

    Any ideas?

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Unusual behavior in Release build

    Erk, I'm really not sure why, but what if you just do something like:

    Code:
    using (DirectoryEntry appPools = new DirectoryEntry(MetabasePath))
    {
        DirectoryEntry newPool = appPools.Children.Add(AppPoolName, "IIsApplicationPool");
        appPools.CommitChanges();
    }
    That is, getting rid of the interior using directive. Is there a good reason you are using it?

    I'm not sure if that will fix it, but that's my first guess at a solution.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center