Static class / method Stop application

I'm having trouble calling a static method from another method.

My static method is in a separate project, but I checked the links and usage statements, and everything seems to be correct. The following is a simplified version.

Static method

namespace Backend
{
    static public class StartUpChecks
    {
        public static void RunAtStart()
        {
            // Calls other static methods and sets application settings
        }
     }
}

Windows form

using Backend;

namespace UI
{
    public partial class mainForm:Form
    {
        public mainForm()
        {
            InitializeComponent();
        }
        private void mainForm_Load(object sender, EventArgs e)
        {
            //MessageBox.Show("It Works");
            StartUpChecks.RunAtStart();
        }
    }
}

When I run the program, it just stops. I set a breakpoint in the OnLoad event handler, but it never hits. If I comment on a MessageBox and comment out a method call, the event fires and a message box appears.

VS. Test() StartUpChecks.RunAtStart(). Test() MessageBox. , , Test().

VS , - .

, ?

---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataSourceManager;
using UserValidator;

namespace Backend
{
    static public class StartUpChecks
    {
        public static void RunAtStart()
        {
            CheckUserAuthorised();
            CheckUserAdmin();
            SetConnection("myApplication");
        }

        private static void SetConnection(string appName)
        {
            AppControl.Connection = ConnectionSetter.SetConnectionString(appName);
        }

        private static void CheckUserAuthorised()
        {
            UserValidation checkMe = new UserValidation(AppControl.Connection);
            AppControl.UserIsAuthorised = checkMe.UserIsAuthorised();
        }

        private static void CheckUserAdmin()
        {
            UserValidation checkMe = new UserValidation(AppControl.Connection);
            AppControl.UserIsAdmin = checkMe.UserIsAdmin();
        }
    }
}
+3
3

VS :

→ → = > CLR ""

→ → → →

+1

64- . , ( OnLoad), .

- Project + Properties, Build, Platform target = x86. VS2010, Edit + Continue. . 64- , Debug + Exceptions, "" Runtime Common Language.

, , .

+1

AppDomain.CurrentDomain.UnhandledException. mainform.

    public MainForm()
    {
        InitializeComponent();
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    }

    void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        //Diagnose the exception here..
    }

Alternatively, you can try using the Windows Live Donsole client debugging and tracking utility for live tracking.

enter image description here

0
source

Source: https://habr.com/ru/post/1796056/


All Articles