简体   繁体   中英

C# WinForm ClickOnce application doesn't work after installation

The ClickOnce app that I've built installs successfully and displays the login screen of the application. However, it won't go to the main form or anywhere when I submit a valid login info. Could it be this code prohibiting it from going through? The target framework is .Net 4.5 and entity framework 6 is the database layer.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
    bool mutexCreated = true;
    using (Mutex mutex = new Mutex(true, Application.ProductName, out mutexCreated))
    {
        if (mutexCreated)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            frmLogin loging = new frmLogin();
            Application.Run(loging);

            if (!loging.UserID.Equals(""))
            {
                Application.Run(new frmMainScreen() { UserID = loging.UserID});
            }
        }
        else
        {
            Process current = Process.GetCurrentProcess();
            foreach (Process process in Process.GetProcessesByName(current.ProcessName))
            {
                if (process.Id != current.Id)
                {
                    MessageBox.Show("Another instance of " + Application.ProductName + " is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    break;
                }
            }
        }
    }
}

I figured it out! The issue was neither to the login nor main form but the entity framework throwing exception on the constructor.

I just followed this blog post entry and added:

var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices); 

to the constructor. Now, it's working like a charm!

Thanks everyone for your response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM