Link to home
Start Free TrialLog in
Avatar of andrewl77
andrewl77

asked on

VS2010 Application Bug

I have an application that has been written for me and i have all the source code.  When i compile and run it i get the following error.  What can be causing this?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.ToolStripMenuItem' to type 'System.Windows.Forms.Control'.
   at Accusoft.FSInvoicesDemo.MDIParent2.localFolderToolStripMenuItem_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
FSInvoicesDemo
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/FSInvoicesDemo.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2104.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2103.2 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
DBOperation
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/DBOperation.DLL
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2102.0 built by: NET47REL1LAST
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_64/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_64/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_64/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
Accusoft.FSInvoices1.Net
    Assembly Version: 1.2.0.116
    Win32 Version: 1.2.0.116
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/Accusoft.FSInvoices1.Net.DLL
----------------------------------------
Accusoft.FSInvoices1.Net&
    Assembly Version: 1.0.0.0
    Win32 Version: 1.2.0.116
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/Accusoft.FSInvoices1.Net.dll
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
SMDiagnostics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/SMDiagnostics/v4.0_4.0.0.0__b77a5c561934e089/SMDiagnostics.dll
----------------------------------------
System.ServiceModel.Internals
    Assembly Version: 4.0.0.0
    Win32 Version: 4.7.2046.0 built by: NET47REL1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.ServiceModel.Internals/v4.0_4.0.0.0__31bf3856ad364e35/System.ServiceModel.Internals.dll
----------------------------------------
ImageGear20.Formats.Pdf
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.Pdf.DLL
----------------------------------------
Accusoft.ScanFixXpress7.Net
    Assembly Version: 7.0.1.1
    Win32 Version: 7.0.1.1
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/Accusoft.ScanFixXpress7.Net.DLL
----------------------------------------
ImageGear20.Core
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Core.DLL
----------------------------------------
ImageGear20.Formats.CameraRaw
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.CameraRaw.DLL
----------------------------------------
ImageGear20.Formats.Common
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.Common.DLL
----------------------------------------
ImageGear20.Formats.Advanced
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.Advanced.DLL
----------------------------------------
ImageGear20.Formats.Office
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.Office.DLL
----------------------------------------
ImageGear20.Formats.Vector
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Formats.Vector.DLL
----------------------------------------
ImageGear20.Presentation
    Assembly Version: 20.4.1018.7298
    Win32 Version: 20.4.1018.7298
    CodeBase: file:///C:/Program%20Files/EASYAP/InvoiceProcess/ImageGear20.Presentation.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Avatar of it_saige
it_saige
Flag of United States of America image

Search for this method name:

localFolderToolStripMenuItem_Click

When you find it, post the code in the method.  The original author performed an illegal cast.

-saige-
Avatar of andrewl77
andrewl77

ASKER

{
            string LocalFolderPath = Properties.Settings.Default.LocalFolderPath;

            if (LocalFolderPath != "")
            {

                FolderLocation = "Local";
                openFileDialog1.InitialDirectory = Properties.Settings.Default.LocalFolderPath;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    // Reset the initial directory to the current file path
                    openFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
                    // Free up the image xpress view before loading the image, try not lose memory
                    //if (imageXView1.Image != null)
                    //{
                    //    imageXView1.Image.Dispose();
                    //    imageXView1.Image = null;
                    //}
                    ClearResultsDisplays();
                    var hDib = IntPtr.Zero;
                    // Get the image
                    try
                    {
                        // Use an image loader here
                        _openFileName = openFileDialog1.FileName;
                        //string FileName= _openFileName.Replace(".msg", ".pdf");
                        //string fileLocation = openFileDialog1.FileName;
                        //File.Copy(openFileDialog1.FileName, FileName, true);
                        //string NFileName=  FileName.Replace(".pdf", "");

                        //string ext = Path.GetExtension(openFileDialog1.FileName);
                        //if (allExtensions.Any(ext.Contains))
                        //{

                        string appPath = Application.StartupPath;
                        string defaaultfilePath = @"Esale.pdf";
                        string pdfurl1 = Path.Combine(appPath, defaaultfilePath);


                       // string pdfurl1 = "E:\\Invoive 6-2-2016\\FSInvoices\\V1.0\\Samples\\DotNet\\C#\\VS2010\\FSInvoicesDemo\\Image\\Esale.pdf";


                        var loader = new ImageLoader(pdfurl1, _fsiLicense)
                             {
                                 PreprocessingOptions = AppPreProcessingOptions.GetOptionsForDisplay()
                             };
                        hDib = loader.ToHdib(true);
                        //imageXView1.Image = Accusoft.ImagXpressSdk.ImageX.FromHdib(imagXpress1, hDib, true);
                        loader.Dispose();
                        //  }
                        SetCursonAndRunInvoiceProcessing();
                        //miRun.Enabled = true;
                        //miValidate.Enabled = true;
                        //miMergeSplit.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        //imageXView1.Image = null;
                        // Free up the hDib we created
                        ExceptionHelper.LogFile(ex.Message, e.ToString(), ((Control)sender).Name, this.FindForm().Name);
                        if (hDib != IntPtr.Zero)
                            ImageLoader.FreeHdib(hDib);
                        MessageBox.Show(@"Error opening image - " + openFileDialog1.FileName + Environment.NewLine +
                                        @"Message - " + ex.Message, @"Error");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Select Local Folder Path Using Configuration Menu!");

                Settings objSettings = new Settings();
                objSettings.Show();
            }
        }
Placing in code tags to make it more readable:
localFolderToolStripMenuItem_Click(Object sender, EventArgs e)
{
	string LocalFolderPath = Properties.Settings.Default.LocalFolderPath;

	if (LocalFolderPath != "")
	{

		FolderLocation = "Local";
		openFileDialog1.InitialDirectory = Properties.Settings.Default.LocalFolderPath;
		if (openFileDialog1.ShowDialog() == DialogResult.OK)
		{
			// Reset the initial directory to the current file path
			openFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
			// Free up the image xpress view before loading the image, try not lose memory
			//if (imageXView1.Image != null)
			//{
			//    imageXView1.Image.Dispose();
			//    imageXView1.Image = null;
			//} 
			ClearResultsDisplays();
			var hDib = IntPtr.Zero;
			// Get the image
			try
			{
				// Use an image loader here
				_openFileName = openFileDialog1.FileName;
				//string FileName= _openFileName.Replace(".msg", ".pdf");
				//string fileLocation = openFileDialog1.FileName;
				//File.Copy(openFileDialog1.FileName, FileName, true);
				//string NFileName=  FileName.Replace(".pdf", "");

				//string ext = Path.GetExtension(openFileDialog1.FileName);
				//if (allExtensions.Any(ext.Contains))
				//{

				string appPath = Application.StartupPath;
				string defaaultfilePath = @"Esale.pdf";
				string pdfurl1 = Path.Combine(appPath, defaaultfilePath);


			   // string pdfurl1 = "E:\\Invoive 6-2-2016\\FSInvoices\\V1.0\\Samples\\DotNet\\C#\\VS2010\\FSInvoicesDemo\\Image\\Esale.pdf";


				var loader = new ImageLoader(pdfurl1, _fsiLicense)
				{
					PreprocessingOptions = AppPreProcessingOptions.GetOptionsForDisplay()
				};
				hDib = loader.ToHdib(true);
				//imageXView1.Image = Accusoft.ImagXpressSdk.ImageX.FromHdib(imagXpress1, hDib, true);
				loader.Dispose();
				//  }
				SetCursonAndRunInvoiceProcessing();
				//miRun.Enabled = true;
				//miValidate.Enabled = true;
				//miMergeSplit.Enabled = true;
			}
			catch (Exception ex)
			{
				//imageXView1.Image = null;
				// Free up the hDib we created
				ExceptionHelper.LogFile(ex.Message, e.ToString(), ((Control)sender).Name, this.FindForm().Name);
				if (hDib != IntPtr.Zero)
					ImageLoader.FreeHdib(hDib);
				MessageBox.Show(@"Error opening image - " + openFileDialog1.FileName + Environment.NewLine +
								@"Message - " + ex.Message, @"Error");
			}
		}
	}
	else
	{
		MessageBox.Show("Please Select Local Folder Path Using Configuration Menu!");

		Settings objSettings = new Settings();
		objSettings.Show();
	}
}

Open in new window


-saige-
The only place I see a cast to control is in the catch of the try block; line 61.  Since we know the sender is a ToolStripMenuItem, this line probably should have read:
ExceptionHelper.LogFile(ex.Message, e.ToString(), ((ToolStripMenuItem)sender).Name, this.FindForm().Name);

Open in new window


Full code:
protected void localFolderToolStripMenuItem_Click(Object sender, EventArgs e)
{
    string LocalFolderPath = Properties.Settings.Default.LocalFolderPath;

    if (LocalFolderPath != "")
    {

        FolderLocation = "Local";
        openFileDialog1.InitialDirectory = Properties.Settings.Default.LocalFolderPath;
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            // Reset the initial directory to the current file path
            openFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
            // Free up the image xpress view before loading the image, try not lose memory
            //if (imageXView1.Image != null)
            //{
            //    imageXView1.Image.Dispose();
            //    imageXView1.Image = null;
            //} 
            ClearResultsDisplays();
            var hDib = IntPtr.Zero;
            // Get the image
            try
            {
                // Use an image loader here
                _openFileName = openFileDialog1.FileName;
                //string FileName= _openFileName.Replace(".msg", ".pdf");
                //string fileLocation = openFileDialog1.FileName;
                //File.Copy(openFileDialog1.FileName, FileName, true);
                //string NFileName=  FileName.Replace(".pdf", "");

                //string ext = Path.GetExtension(openFileDialog1.FileName);
                //if (allExtensions.Any(ext.Contains))
                //{

                string appPath = Application.StartupPath;
                string defaaultfilePath = @"Esale.pdf";
                string pdfurl1 = Path.Combine(appPath, defaaultfilePath);


                // string pdfurl1 = "E:\\Invoive 6-2-2016\\FSInvoices\\V1.0\\Samples\\DotNet\\C#\\VS2010\\FSInvoicesDemo\\Image\\Esale.pdf";


                var loader = new ImageLoader(pdfurl1, _fsiLicense)
                {
                    PreprocessingOptions = AppPreProcessingOptions.GetOptionsForDisplay()
                };
                hDib = loader.ToHdib(true);
                //imageXView1.Image = Accusoft.ImagXpressSdk.ImageX.FromHdib(imagXpress1, hDib, true);
                loader.Dispose();
                //  }
                SetCursonAndRunInvoiceProcessing();
                //miRun.Enabled = true;
                //miValidate.Enabled = true;
                //miMergeSplit.Enabled = true;
            }
            catch (Exception ex)
            {
                //imageXView1.Image = null;
                // Free up the hDib we created
                ExceptionHelper.LogFile(ex.Message, e.ToString(), ((ToolStripMenuItem)sender).Name, this.FindForm().Name);
                if (hDib != IntPtr.Zero)
                    ImageLoader.FreeHdib(hDib);
                MessageBox.Show(@"Error opening image - " + openFileDialog1.FileName + Environment.NewLine +
                                @"Message - " + ex.Message, @"Error");
            }
        }
    }
    else
    {
        MessageBox.Show("Please Select Local Folder Path Using Configuration Menu!");

        Settings objSettings = new Settings();
        objSettings.Show();
    }
}

Open in new window


-saige-
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.