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:

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 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.