Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Coverting from WinForm - Runtime error - 'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll Parameter count mismatch

$
0
0

This is an odd issue. When working on this yesterday, the program would stop, highlight the area of code I was working on and present "NullReferenceException," and linked to this page.

NullReferenceException Class

TODAY, without changes I am getting the error in the title. 

I am learning c#, and found an application in an area I have need to learn.

After coming along fine, and using this example on learning more, I ran into issues with limitations in Windows Forms, thus started the change to WPF.

The original code I am working with can be found here:

Paste Bine: PCCom.SerialCommunication Version 1.0.0.0

You can download the entire original project, if you wish, at

www.dreamincode.net - Serial Cmmunications Project

Here is the section of code presenting the error. The error occurs when "return true;" is executed.

 #region OpenPort
        public bool OpenPort()
        {
            try
            {
                //first check if the port is already open
                //if its open then close it
                if (comPort.IsOpen == true) comPort.Close();
                //set the properties of our SerialPort Object
                comPort.BaudRate = int.Parse(_baudRate);    //BaudRate
                comPort.DataBits = int.Parse(_dataBits);    //DataBits
                comPort.StopBits = (StopBits)Enum.Parse(typeof(StopBits), _stopBits);    //StopBits
                comPort.Parity = (Parity)Enum.Parse(typeof(Parity), _parity);    //Parity
                comPort.PortName = _portName;   //PortName
                //now open the port
                comPort.Open();
              
                return true;
            }
            catch (Exception ex)
            {
                DisplayData(ex.Message);
                return false;
            }
        }
        #endregion

I have no idea on what is going on with this. Some helpful explanations would be great.

The error I was having yesterday, was in another section of the program:

What I am currently working on is:

private RichTextBox _displayWindow;

I have since changed to:

private TextBox _displayWindow;

And the code I have been working on to convert to wpf which generated the NullReferenceException

 private void DisplayData(string msg)
        {
            _displayWindow.Dispatcher.Invoke(new EventHandler(delegate
            {
                _displayWindow.SelectedText = string.Empty;
                _displayWindow.AppendText(msg);
                _displayStatus.ScrollToLine(_displayStatus.GetLineIndexFromCharacterIndex(_displayStatus.SelectionSta‌​rt));
                //_displayWindow.ScrollToCaret();
               
            }));
        }

Thanks


Viewing all articles
Browse latest Browse all 18858

Trending Articles