Custom Application Error when installed on client Workstation

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 941 Views - Last Post: 13 December 2019 - 02:21 PM Rate Topic: -----

#1 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Custom Application Error when installed on client Workstation

Posted 05 December 2019 - 09:46 AM

The application was developed in VS Community 2017 and runs fine with no error on the development machine.

However after publishing and installing on a different workstation, I am having issues running it.

Both the development workstation and client workstation are Windows 7 64-bit. The application was developed with a target framework of .NET Framework 4.6.1 and the client has .NET Framework 4.6.1 installed.

When running on the client machine I am getting the following in the Event Viewer:

Application: PAF_Reporter.exe
Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.Security.SecurityException



at System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean)
at System.Windows.Forms.Control.Invoke(System.Delegate, System.Object[])
at System.Windows.Forms.Control.Invoke(System.Delegate)
at PAF_Reporter.Form_Login.DisplayLoginSplash()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

Is This A Good Question/Topic? 0
  • +

Replies To: Custom Application Error when installed on client Workstation

#2 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 05 December 2019 - 10:28 AM

After looking at the above it seems it is having a problem with my login form, as I see "at PAF_Reporter.Form_Login.DisplayLoginSplash()" in the reported error stack.

I am not able to attach or insert the code for my login form for some reason.

But the issue seems to be .NET Framework related, and after researching a bit, some of the information I gathered indicates possibly being related to the.NET security model and more specifically an issue with Code Access Security (CAS).

I may totally be on the wrong path here and it may be a basic issue with a simple fix so I am hoping to get some insight, guidance and help in determining the issue here and the best way to resolve it.

Any help would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#3 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 05 December 2019 - 05:43 PM



This post has been edited by Narflak: 05 December 2019 - 05:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Custom Application Error when installed on client Workstation

Posted 05 December 2019 - 06:56 PM

If your code has the method named "Substring" in it, try changing it to something like "Sub_string" so that you can post here. There is a forum bug where it blocks posting if it sees that word thinking that it's malicious script.
Was This Post Helpful? 0
  • +
  • -

#5 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 06 December 2019 - 02:21 PM

When running on the client machine I am getting the following in the Event Viewer:

Application: PAF_Reporter.exe
Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.Security.SecurityException



at System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean)
at System.Windows.Forms.Control.Invoke(System.Delegate, System.Object[])
at System.Windows.Forms.Control.Invoke(System.Delegate)
at PAF_Reporter.Form_Login.DisplayLoginSplash()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()


After looking at the above it seems it is having a problem with my login form, as I see "at PAF_Reporter.Form_Login.DisplayLoginSplash()" in the reported error stack.

My Login_Form.cs containing the method DisplayLoginSplash() can be viewed at the following link:

Login_Form

But the issue seems to be .NET Framework related, and after researching a bit, some of the information I gathered indicates possibly being related to the.NET security model and more specifically an issue with Code Access Security (CAS).

I may totally be on the wrong path here and it may be a basic issue with a simple fix so I am hoping to get some insight, guidance and help in determining the issue here and the best way to resolve it.

Any help would be greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15496
  • View blog
  • Posts: 62,055
  • Joined: 12-June 08

Re: Custom Application Error when installed on client Workstation

Posted 06 December 2019 - 02:33 PM

Please don't just duplicate your posts above.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Custom Application Error when installed on client Workstation

Posted 06 December 2019 - 02:43 PM

How is your code being deployed to the client machine? If you are using ClickOnce, be aware the ClickOnce applications run in the same context as the web site from which the application was downloaded from. So if it was downloaded from the "Internet" zone (and nobody has messed with the default zone settings), then your code will not be running with Full Trust and CAS policies will definitely kick in.

I suggest trying to do an XCopy deployment first to make sure that it is not ClickOnce's CAS policies that is causing your program to fail.

As an aside, firing off another thread to bring up another dialog/form is a terrible practice. Just use the primary UI thread.

        private void btn_Login_Click(object sender, EventArgs e)
        {

            try
            {

                Thread threadInput = new Thread(DisplayLoginSplash);
                threadInput.Start();
            }

            catch (Exception ex)
            {

                DisplayError.DisplayErr(ex);
            }


            

        }


        private void DisplayLoginSplash()
        {
            SetLoading(true);

            
            Thread.Sleep(3000);

            this.Invoke((MethodInvoker)delegate
            {

                string usr = txt_username.Text;
                string psw = txt_password.Text;
                con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=paf_users.accdb");
                cmd = new OleDbCommand();
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "SELECT * FROM Login where Username='" + txt_username.Text + "' AND Password='" + txt_password.Text + "'";
                dr = cmd . ExecuteReader();
                if (dr.Read())
                {
                    Form1 f1 = new Form1();

                    this.Hide();
                    f1.Show();


                }
                else
                {
                    MessageBox.Show("Username or password is incorrect");
                }

                con.Close();



            });

            SetLoading(false);
        }



Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Custom Application Error when installed on client Workstation

Posted 06 December 2019 - 02:56 PM

Apparently the forum software is also flagging the string cmd dot exe.
Was This Post Helpful? 0
  • +
  • -

#9 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 09 December 2019 - 08:07 AM

I published as "Full trust application" so I think the ClickOnce's CAS policies should be ok.

However, I tried something and bypassed the login form, rebuilt and reinstalled on client machine and now receive a different error in event viewer.


The error is as follows:

Event Viewer Error:
Application: PAF_Reporter.exe
Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.Security.SecurityException
at System.Diagnostics.EventLog.FindSourceRegistration(System.String, System.String, Boolean, Boolean)
at System.Diagnostics.EventLog.SourceExists(System.String, System.String, Boolean)
at System.Diagnostics.EventLogInternal.VerifyAndCreateSource(System.String, System.String)
at System.Diagnostics.EventLogInternal.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32, Int16, Byte[])
at System.Diagnostics.EventLog.WriteEntry(System.String, System.Diagnostics.EventLogEntryType, Int32, Int16)
at PAF_Reporter.EventLogger.LogFile()
at PAF_Reporter.Form1..ctor()
at PAF_Reporter.Program+<>c.<Main>g__StartNewStaThread|0_0/>/>()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

Noticing in the above that the issue seems to be something related to my EventLogger.LogFile(), I am providing the code below:



namespace PAF_Reporter
{
    public class EventLogger
    {

        public static void LogFile()
        {

            using (EventLog eventLog = new EventLog("Application"))

            {
                eventLog.Source = "PAF Reporter Application";

                eventLog.WriteEntry("PAF Reporter v2 Events", EventLogEntryType.Information, 101, 1);

            }

        }
    }
}





I then call LogFile() from Form1 using the below code:

 public Form1()
        {
            InitializeComponent();

           
           
            // Start Writing to Windows Event Log 

            EventLogger.LogFile();


        }





Is there something wrong with the way I am doing this? Do you notice anything here? Again, thank you for your insight and help.
Was This Post Helpful? 0
  • +
  • -

#10 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 09 December 2019 - 08:13 AM

View PostSkydiver, on 06 December 2019 - 04:43 PM, said:

How is your code being deployed to the client machine? If you are using ClickOnce, be aware the ClickOnce applications run in the same context as the web site from which the application was downloaded from. So if it was downloaded from the "Internet" zone (and nobody has messed with the default zone settings), then your code will not be running with Full Trust and CAS policies will definitely kick in.

I suggest trying to do an XCopy deployment first to make sure that it is not ClickOnce's CAS policies that is causing your program to fail.

As an aside, firing off another thread to bring up another dialog/form is a terrible practice. Just use the primary UI thread.

        private void btn_Login_Click(object sender, EventArgs e)
        {

            try
            {

                Thread threadInput = new Thread(DisplayLoginSplash);
                threadInput.Start();
            }

            catch (Exception ex)
            {

                DisplayError.DisplayErr(ex);
            }


            

        }


        private void DisplayLoginSplash()
        {
            SetLoading(true);

            
            Thread.Sleep(3000);

            this.Invoke((MethodInvoker)delegate
            {

                string usr = txt_username.Text;
                string psw = txt_password.Text;
                con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=paf_users.accdb");
                cmd = new OleDbCommand();
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "SELECT * FROM Login where Username='" + txt_username.Text + "' AND Password='" + txt_password.Text + "'";
                dr = cmd . ExecuteReader();
                if (dr.Read())
                {
                    Form1 f1 = new Form1();

                    this.Hide();
                    f1.Show();


                }
                else
                {
                    MessageBox.Show("Username or password is incorrect");
                }

                con.Close();



            });

            SetLoading(false);
        }





I will clean up the method to use the primary UI thread as you suggested. Thank you. Could that possibly have been the cause for the first error reported in the event viewer?
Was This Post Helpful? 0
  • +
  • -

#11 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Custom Application Error when installed on client Workstation

Posted 09 December 2019 - 03:19 PM

View PostNarflak, on 09 December 2019 - 10:07 AM, said:

Is there something wrong with the way I am doing this? Do you notice anything here? Again, thank you for your insight and help.

Did you see the big warning in the documentation for EventLog?

Quote

Note

Starting with Windows Vista, you must run this application as an administrator.


Although the warning is particularly relevant to the sample code presented there, in general if the event log that you are trying to write to does not currently exist, then you'll need admin rights to create the initial container.

See this blog post: Logging to the Windows EventLog without administrative privileges in .Net

View PostNarflak, on 09 December 2019 - 10:13 AM, said:

I will clean up the method to use the primary UI thread as you suggested. Thank you. Could that possibly have been the cause for the first error reported in the event viewer?

I doubt it.
Was This Post Helpful? 0
  • +
  • -

#12 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 10 December 2019 - 10:59 AM

By using "Run As Administrator" on the client machine when launching the application, that should resolve the issue related to the eventlog. Correct?

This post has been edited by Skydiver: 10 December 2019 - 11:04 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7239
  • View blog
  • Posts: 24,538
  • Joined: 05-May 12

Re: Custom Application Error when installed on client Workstation

Posted 10 December 2019 - 11:06 AM

There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area. If you really need to quote, trim down to the specific thing you want to address.

It should. As I recall, you really just need to run as admin on first run so that the event log containers are setup correctly in the registry. I think that succeeding runs should work without being elevated. It's been a while since I've had to deal with this. You'll need to test.
Was This Post Helpful? 0
  • +
  • -

#14 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 10 December 2019 - 11:17 AM

Ok. I will try it out. Thank you for the insight.
Was This Post Helpful? 0
  • +
  • -

#15 Narflak   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 19-November 18

Re: Custom Application Error when installed on client Workstation

Posted 11 December 2019 - 12:35 PM

View PostNarflak, on 09 December 2019 - 10:13 AM, said:

View PostSkydiver, on 06 December 2019 - 04:43 PM, said:

How is your code being deployed to the client machine? If you are using ClickOnce, be aware the ClickOnce applications run in the same context as the web site from which the application was downloaded from. So if it was downloaded from the "Internet" zone (and nobody has messed with the default zone settings), then your code will not be running with Full Trust and CAS policies will definitely kick in.

I suggest trying to do an XCopy deployment first to make sure that it is not ClickOnce's CAS policies that is causing your program to fail.

As an aside, firing off another thread to bring up another dialog/form is a terrible practice. Just use the primary UI thread.

        private void btn_Login_Click(object sender, EventArgs e)
        {

            try
            {

                Thread threadInput = new Thread(DisplayLoginSplash);
                threadInput.Start();
            }

            catch (Exception ex)
            {

                DisplayError.DisplayErr(ex);
            }


            

        }


        private void DisplayLoginSplash()
        {
            SetLoading(true);

            
            Thread.Sleep(3000);

            this.Invoke((MethodInvoker)delegate
            {

                string usr = txt_username.Text;
                string psw = txt_password.Text;
                con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=paf_users.accdb");
                cmd = new OleDbCommand();
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "SELECT * FROM Login where Username='" + txt_username.Text + "' AND Password='" + txt_password.Text + "'";
                dr = cmd . ExecuteReader();
                if (dr.Read())
                {
                    Form1 f1 = new Form1();

                    this.Hide();
                    f1.Show();


                }
                else
                {
                    MessageBox.Show("Username or password is incorrect");
                }

                con.Close();



            });

            SetLoading(false);
        }





I will clean up the method to use the primary UI thread as you suggested. Thank you. Could that possibly have been the cause for the first error reported in the event viewer?


Rather than using a new thread , I changed it from

 Thread threadInput = new Thread(DisplayLoginSplash);
                threadInput.Start();




To just:

DisplayLoginSplash();



This seems to work fine, but I now notice that the animated picLoader is not being displayed.

The code relevant to the picLoader is below:

public Form_Login()
        {
            InitializeComponent();

            picLoader.Visible = false;
        }




    private void SetLoading(bool displayLoader)
        {
            if (displayLoader)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    picLoader.Visible = true;
                    this.Cursor = Cursors.WaitCursor;
                });
            }
            else
            {
                this.Invoke((MethodInvoker)delegate
                {
                    picLoader.Visible = false;
                    this.Cursor = Cursors.Default;
                });
            }
        }



You can see that SetLoading is used in the DisplayLoginSplash method. This is not a show stopper, but does something need to be modified for this to work after just using

 DisplayLoginSplash();



to call the method, rather than using a new thread like before with,

 Thread threadInput = new Thread(DisplayLoginSplash);
                threadInput.Start();


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2