title: Unable to debug from VS2010
body: <p>I am trying to compile the code below but and am now unable to debug. Any idea ?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Microsoft.AnalysisServices;
  using System.Runtime.Serialization;
  
  namespace SqlBi.Tools {
      /// &lt;summary&gt;
      /// MdxScriptUpdater handles the manage of custom 
      /// MDX statements into an existing cube
      /// Use in this way:
      /// 1 - Create a MdxScriptUpdater instance specifying a server name
      /// 2 - Add MDX statements you want to put into the cube adding strings to MdxCommands collection
      /// 3 - Call Update method passing the name of database and cube - you have to use object IDs instead of displayed names!
      /// &lt;/summary&gt;
      public class MdxScriptUpdater : IDisposable {
          /// &lt;summary&gt;
          /// Type of update
          /// &lt;/summary&gt;
          public enum UpdateType {
              /// &lt;summary&gt;
              /// Delete existing commands and insert the new ones
              /// &lt;/summary&gt;
              DeleteAndInsert, 
              /// &lt;summary&gt;
              /// Only delete existing commands
              /// &lt;/summary&gt;
              DeleteOnly, 
              /// &lt;summary&gt;
              /// Only insert new commands (be careful, you can create duplicates!)
              /// &lt;/summary&gt;
              InsertOnly
          };
  
          private string _marker = "/* AUTO-GENERATED */";
          private Server _serverConnection = null;
          private bool _ownedServer = false;
          private List&lt;string&gt; _mdxCommands;
  
          /// &lt;summary&gt;
          /// Marker is a comment that is put in front of the MDX statement to recognize managed MDX statements
          /// &lt;/summary&gt;
          public string Marker {
              get { return this._marker; }
              set { this._marker = value; }
          }
  
          /// &lt;summary&gt;
          /// This is the connection to the server. 
          /// It is auto generated by the constructor but you can use your own connection, if you want
          /// &lt;/summary&gt;
          public Server ServerConnection {
              get { return this._serverConnection; }
              set {
                  if (this._serverConnection != null &amp;&amp; _ownedServer) {
                      try {
                          this.Dispose();
                      }
                      finally {
                          _ownedServer = false;
                      }
                  }
                  this.ServerConnection = value;
                  _ownedServer = true;
              }
          }
  
          /// &lt;summary&gt;
          /// List of Mdx statements to add/update into the cube
          /// Populate the list before calling the Update(...) method
          /// &lt;/summary&gt;
          public List&lt;string&gt; MdxCommands {
              get { return this._mdxCommands; }
              set { this._mdxCommands = value; }
          }
  
          /// &lt;summary&gt;
          /// Default constructor - connection is not defined
          /// &lt;/summary&gt;
          public MdxScriptUpdater() {
              this._mdxCommands = new List&lt;string&gt;();
          }
  
          /// &lt;summary&gt;
          /// Constructor that connects to the specified server
          /// &lt;/summary&gt;
          /// &lt;param name="serverName"&gt;Name of the Analsys Services server instance (SERVERNAME or SERVERNAME\INSTANCE)&lt;/param&gt;
          public MdxScriptUpdater( string serverName ) : this() {
              this._serverConnection = new Server();
              this.ServerConnection.Connect( serverName );
          }
  
          /// &lt;summary&gt;
          /// Apply updates to the specified cube
          /// Deletes existing managed Mdx commands and insert the ones in MdxCommands string collection
          /// &lt;/summary&gt;
          /// &lt;param name="databaseName"&gt;Name (ID) of the Database&lt;/param&gt;
          /// &lt;param name="cubeName"&gt;Name (ID) of the Cube&lt;/param&gt;
          public void Update( string databaseName, string cubeName ) {
              Update( databaseName, cubeName, UpdateType.DeleteAndInsert );
          }
  
          /// &lt;summary&gt;
          /// Apply updates to the specified cube
          /// &lt;/summary&gt;
          /// &lt;param name="databaseName"&gt;Name (ID) of the Database&lt;/param&gt;
          /// &lt;param name="cubeName"&gt;Name (ID) of the Cube&lt;/param&gt;
          /// &lt;param name="updateType"&gt;Type of update&lt;/param&gt;
          public void Update( string databaseName, string cubeName, UpdateType updateType ) {
              Database db = ServerConnection.Databases[databaseName];
              Cube cube = db.Cubes[cubeName];
              Update( cube, updateType );
          }
  
          /// &lt;summary&gt;
          /// Apply updates to the specified cube
          /// &lt;/summary&gt;
          /// &lt;param name="cube"&gt;Cube object&lt;/param&gt;
          public void Update( Cube cube ) {
              Update( cube, UpdateType.DeleteAndInsert );
          }
  
          /// &lt;summary&gt;
          /// Apply updates to the specified cube
          /// &lt;/summary&gt;
          /// &lt;param name="cube"&gt;Cube object&lt;/param&gt;
          /// &lt;param name="updateType"&gt;Type of update&lt;/param&gt;
          public void Update( Cube cube, UpdateType updateType ) {
              // Look for the default MDX Script object
              foreach( MdxScript script in cube.MdxScripts) {
                  if (script.DefaultScript) {
                      Update( script, updateType );
                      cube.Update();
                      return;
                  }
              }
              throw new MdxScriptUpdaterException( "Default script not found" );
          }
  
          /// &lt;summary&gt;
          /// Update an MdxScript
          /// Deletes existing managed Mdx commands and insert the ones in MdxCommands string collection
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          /// &lt;param name="updateType"&gt;Type of update&lt;/param&gt;
          public void Update( MdxScript script, UpdateType updateType ) {
              if (updateType == UpdateType.DeleteAndInsert || updateType == UpdateType.DeleteOnly) {
                  DeleteMarkedCommands( script );
              }
              if (updateType == UpdateType.DeleteAndInsert || updateType == UpdateType.InsertOnly) {
                  InsertMarkedCommands( script );
              }
              script.Update();
          }
  
          /// &lt;summary&gt;
          /// Deletes existing managed Mdx commands using default Marker comment string
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          public void DeleteMarkedCommands( MdxScript script ) {
              DeleteMarkedCommands( script, Marker );
          }
  
          /// &lt;summary&gt;
          /// Deletes existing managed Mdx commands using a custom Marker comment string
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          /// &lt;param name="marker"&gt;Custom marker comment string&lt;/param&gt;
          public static void DeleteMarkedCommands( MdxScript script, string marker ) {
              for( int i = script.Commands.Count - 1; i &gt;= 0; i-- ) {
                  if (script.Commands[i].Text.Contains( marker )) {
                      script.Commands.RemoveAt( i );
                  }
              }
          }
  
          /// &lt;summary&gt;
          /// Insert managed commands of MdxCommands string collection
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          public void InsertMarkedCommands( MdxScript script ) {
              InsertMarkedCommands( script, this.MdxCommands, Marker );
          }
  
          /// &lt;summary&gt;
          /// Insert managed commands of a custom string collection
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          /// &lt;param name="commands"&gt;Custom string collection of Mdx commands to insert&lt;/param&gt;
          public void InsertMarkedCommands( MdxScript script, IEnumerable&lt;string&gt; commands ) {
              InsertMarkedCommands( script, commands, Marker );
          }
  
          /// &lt;summary&gt;
          /// Insert managed commands of MdxCommands string collection using a custom Marker comment string
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          /// &lt;param name="marker"&gt;Custom marker comment string&lt;/param&gt;
          public void InsertMarkedCommands( MdxScript script, string marker ) {
              InsertMarkedCommands( script, this.MdxCommands, marker );
          }
  
          /// &lt;summary&gt;
          /// Insert managed commands of a string collection using a custom Marker comment string
          /// &lt;/summary&gt;
          /// &lt;param name="script"&gt;MdxScript to update&lt;/param&gt;
          /// &lt;param name="commands"&gt;Custom string collection of Mdx commands to insert&lt;/param&gt;
          /// &lt;param name="marker"&gt;Custom marker comment string&lt;/param&gt;
          public static void InsertMarkedCommands( MdxScript script, IEnumerable&lt;string&gt; commands, string marker ) {
              foreach( string mdxCommand in commands ) {
                  Command cmd = new Command();
                  cmd.Text = marker + mdxCommand;
                  script.Commands.Add( cmd );
              }
          }
  
          #region IDisposable Members
  
          public void Dispose() {
              if (this.ServerConnection != null &amp;&amp; _ownedServer) {
                  this.ServerConnection.Disconnect();
                  this.ServerConnection.Dispose();
              }
              // Write directly to private member, skip the property setter
              this._serverConnection = null;
          }
  
          #endregion
      }
  
      public class MdxScriptUpdaterException : Exception {
          public MdxScriptUpdaterException() : base() {}
          public MdxScriptUpdaterException( string message ) : base( message ) {}
          public MdxScriptUpdaterException( string message, Exception innerException ) : base( message, innerException ) {}
          protected MdxScriptUpdaterException( SerializationInfo info, StreamingContext context ) : base( info, context ) {}
      }
  }
  </code></pre>
  
  <p>Program.cs</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Text;
  using SqlBi.Tools;
  using System.IO;
  
  namespace SqlBi.Tools {
      class DemoMdxScriptUpdater {
          static void Main( string[] args ) {
              Demo();
          }
          static void Demo() {
              MdxScriptUpdater updater = new MdxScriptUpdater("test");
  
              string ScriptMdx = File.ReadAllText(@"D:\\ScriptMdx.txt");
              //Console.WriteLine("--- Contents of file.txt: ---");
              //Console.WriteLine(ScriptMdx);
              updater.MdxCommands.Add(ScriptMdx);
  
              updater.Update("BI", "BI1"); 
  
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>'MdxScriptUpdater.vshost.exe' (Managed (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Users\Desktop\HaysDW\05.Tools\MdxScriptUpdater\bin\Debug\MdxScriptUpdater.vshost.exe',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\Microsoft.AnalysisServices\11.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\Microsoft.AnalysisServices.AdomdClient\11.0.0.0__89845dcd8080cc91\Microsoft.AnalysisServices.AdomdClient.dll', Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. The thread 'vshost.NotifyLoad' (0x5840) has
    exited with code 0 (0x0). The thread 'vshost.LoadReference' (0x7b2c)
    has exited with code 0 (0x0). 'MdxScriptUpdater.vshost.exe' (Managed
    (v2.0.50727)): Loaded
    'C:\Users\Desktop\HaysDW\05.Tools\MdxScriptUpdater\bin\Debug\MdxScriptUpdater.exe',
    Symbols loaded. 'MdxScriptUpdater.vshost.exe' (Managed (v2.0.50727)):
    Loaded
    'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll',
    Skipped loading symbols. Module is optimized and the debugger option
    'Just My Code' is enabled. The thread 'vshost.RunParkingWindow'
    (0x6e88) has exited with code 0 (0x0). The thread '' (0x4a9c) has
    exited with code 0 (0x0). The program '[4784]
    MdxScriptUpdater.vshost.exe: Managed (v2.0.50727)' has exited with
    code 0 (0x0). The program '[4784] MdxScriptUpdater.vshost.exe: Program
    Trace' has exited with code 0 (0x0).</p>
  </blockquote>