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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:15:18+00:00 2026-05-23T19:15:18+00:00

I am developing a WPF app that contains a webbrowser control that loads a

  • 0

I am developing a WPF app that contains a webbrowser control that loads a silverlight application. I would like to be able to launch the app from visual studio (F5) and have the debugger attach to the silverlight code. However, I’ve not had any luck with this.

The best I can currently do is to launch the app without attaching, then once it is up and running, attach to the process manually with silverlight as the specified type of code to debug, and this works. (When I cause the web browser control to load the silverlight app, it will hit breakpoints in my silverlight code). I’ve written some macros to automate this launching/attaching somewhat, but it still isn’t the best.

I’ve tried specifying the WPF app as the external program to run when launching/debugging the silverlight app, but Visual Studio attaches to the process wanting to debug the managed .NET code.

Any ideas? Ideally, I would really like to attach to the process and debug both the managed .NET and the silverlight code, but I don’t think this is possible. I’d really like to automatically be attached to the silverlight code at launch so that I can easily debug all issues with the silverlight app, including those that occur on load.

  • 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-23T19:15:19+00:00Added an answer on May 23, 2026 at 7:15 pm

    Thanks for your ideas Brandorf and fatty. Brandorf’s almost gets me to where I wanted to go, but does require that my SL app be capable of running on its own. I really want to have only the one app, which is both wpf and silverlight, with the SL side being debugged.

    A long time after I asked this question (I forgot I had asked it here), I actually pieced together a solution that I’m really happy with. I use visual studio automation within the WPF/.NET side of my app, to find all running instances of visual studio, figure out which one produced my exe (since it typically sits in a folder below the vcproj/sln folder), and then use visual studio automation to have that VS attach to the app, debugging silverlight code. After this is done, I then load my silverlight content.

    It works really well. You end up with an app that goes and finds a debugger to attach to itself every time it runs (so you probably want this code only in a debug build, or somehow able to be turned off). So you just launch the app with ctrl-F5 (launch without debugging) from visual studio whenever you want to debug the silverlight side.

    Here’s my code:

    #if DEBUG
    
    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Runtime.InteropServices;
    using System.IO;
    
    namespace Launcher
    {
        //The core methods in this class to find all running instances of VS are
        //taken/inspired from
        //http://www.codeproject.com/KB/cs/automatingvisualstudio.aspx
        class DebuggingAutomation
        {
            [DllImport("ole32.dll")]
            private static extern int GetRunningObjectTable(int reserved,
                                      out UCOMIRunningObjectTable prot);
    
            [DllImport("ole32.dll")]
            private static extern int CreateBindCtx(int reserved,
                                          out UCOMIBindCtx ppbc);
            ///<summary>
            ///Get a snapshot of the running object table (ROT).
            ///</summary>
            ///<returns>
            ///A hashtable mapping the name of the object
            ///in the ROT to the corresponding object
            ///</returns>
            private static Hashtable GetRunningObjectTable()
            {
                Hashtable result = new Hashtable();
    
                int numFetched;
                UCOMIRunningObjectTable runningObjectTable;
                UCOMIEnumMoniker monikerEnumerator;
                UCOMIMoniker[] monikers = new UCOMIMoniker[1];
    
                GetRunningObjectTable(0, out runningObjectTable);
                runningObjectTable.EnumRunning(out monikerEnumerator);
                monikerEnumerator.Reset();
    
                while (monikerEnumerator.Next(1, monikers, out numFetched) == 0)
                {
                    UCOMIBindCtx ctx;
                    CreateBindCtx(0, out ctx);
    
                    string runningObjectName;
                    monikers[0].GetDisplayName(ctx, null, out runningObjectName);
    
                    object runningObjectVal;
                    runningObjectTable.GetObject(monikers[0], out runningObjectVal);
    
                    result[runningObjectName] = runningObjectVal;
                }
    
                return result;
            }
    
            /// <summary>
            /// Get a table of the currently running instances of the Visual Studio .NET IDE.
            /// </summary>
            /// <param name="openSolutionsOnly">
            /// Only return instances that have opened a solution
            /// </param>
            /// <returns>
            /// A list of the ides (as DTE objects) present in
            /// in the running object table to the corresponding DTE object
            /// </returns>
            private static List<EnvDTE.DTE> GetIDEInstances(bool openSolutionsOnly)
            {
                var runningIDEInstances = new List<EnvDTE.DTE>();
                Hashtable runningObjects = GetRunningObjectTable();
    
                IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator();
                while (rotEnumerator.MoveNext())
                {
                    string candidateName = (string)rotEnumerator.Key;
                    if (!candidateName.StartsWith("!VisualStudio.DTE"))
                        continue;
    
                    EnvDTE.DTE ide = rotEnumerator.Value as EnvDTE.DTE;
                    if (ide == null)
                        continue;
    
                    if (openSolutionsOnly)
                    {
                        try
                        {
                            string solutionFile = ide.Solution.FullName;
                            if (!String.IsNullOrEmpty(solutionFile))
                            {
                                runningIDEInstances.Add(ide);
                            }
                        }
                        catch { }
                    }
                    else
                    {
                        runningIDEInstances.Add(ide);
                    }
                }
                return runningIDEInstances;
            }
    
            internal static void AttachDebuggerIfPossible()
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    //Probably debugging host (Desktop .NET side), so don't try to attach to silverlight side
                    return;
                }
                var ides = GetIDEInstances(true);
                var fullPathToAssembly = System.Reflection.Assembly.GetExecutingAssembly().Location;
                var potentials = new List<EnvDTE.DTE>();
                foreach (var ide in ides)
                {
                    var solutionPath = ide.Solution.FullName;
                    var topLevelSolutionDir = Path.GetDirectoryName(solutionPath);
                    var assemblyName = fullPathToAssembly;
                    if (assemblyName.StartsWith(topLevelSolutionDir, StringComparison.OrdinalIgnoreCase))
                    {
                        potentials.Add(ide);
                    }
                }
    
                EnvDTE.DTE chosenIde = null;
                //If you have multiple ides open that can match your exe, you can come up with a scheme to pick a particular one
                //(eg, put a file like solution.sln.pickme next to the solution whose ide you want to debug). If this is not a
                //concern, just pick the first match.
                if (potentials.Count > 0)
                {
                    chosenIde = potentials[0];
                }
                var dbg = chosenIde != null ? (EnvDTE80.Debugger2)chosenIde.Debugger : null;
    
                if (dbg != null)
                {
                    var trans = dbg.Transports.Item("Default");
    
                    var proc = (EnvDTE80.Process2)dbg.GetProcesses(trans, System.Environment.MachineName).Item(Path.GetFileName(fullPathToAssembly));
                    var engines = new EnvDTE80.Engine[1];
                    engines[0] = trans.Engines.Item("Silverlight");
    
                    proc.Attach2(engines);
                }
            }
        }
    }
    #endif 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that you are developing a custom control in WPF that contains internally some
I'm developing a light-weight WPF MVVM framework, and would like to be able to
I'm considering developing a WPF application, to be hosted by a legacy Windows app
After developing a WPF application without Source Control, I decided to add the solution
I am developing a WPF kiosk like client that will be deployed on an
I'm developing a networked WPF application with the MVVM pattern and it seems that
I am developing a map control in WPF with C#. I am using a
I'm developing a WinForms application (.Net 3.5, no WPF) where I want to be
I'm developing a WPF app using MVVM. Most of my views have only xaml
I am developing a WPF app using MVVM and need some help. for the

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.