Can't break in global.asax / Application_Start

后端 未结 9 1153
名媛妹妹
名媛妹妹 2021-02-01 16:49

I got a break point on the first line of Application_Start(), but Visual Studio wont break on it.

Visual Studio have attached itself to the IIS working proc

相关标签:
9条回答
  • 2021-02-01 17:44

    I've got around this problem before by doing this:

    1. Run a clean on my solution (Right click the solution node and click clean)
    2. Close solution
    3. File -> Exit on visual studio
    4. If you have multiple instances of visual studio running then exit out of all instances. Ensure "devenv.exe" is not listed in the processes in task manager
    5. Delete the user options file (.suo), usually in the same directory as your solution (.sln) file
    6. Recycle IIS worker process or if using the development server, kill that process

    Now open your solution and give it a shot. (keep your fingers crossed :))

    0 讨论(0)
  • 2021-02-01 17:45

    Place this line in your Application_Start().

    Debugger.Break();
    

    This will present you with a dialog which will allow you to select a debugger. You might need to restart the application pool.

    0 讨论(0)
  • 2021-02-01 17:46

    If using IISEXPRESS is not an option, as @David Perlman mentions, I would go for a Logger. Log4Net or NLog are both good. It's good to have a logger in the longrun, for instance in production environments.

    namespace DataService
    {
        using NLog;
        public class Global : System.Web.HttpApplication
        {
            private Logger log; 
            protected void Application_Start(object sender, EventArgs e)
            {
                LogManager.LoadConfiguration("nlog.config");
                log = LogManager.GetCurrentClassLogger(); 
                log.Error($"Read this line in the log specified in nlog.config");
            }
    
    0 讨论(0)
提交回复
热议问题