7 Replies - 1054 Views - Last Post: 10 September 2019 - 01:34 PM Rate Topic: -----

#1 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

VB.net parameter count mismatch

Posted 06 September 2019 - 06:05 AM

Hello all
I am using reflection to try and write the property data for a class to a file, but I am getting a parameter count mismatch when the loop gets to the class objects inside the base class.
Currently outputting to the debug output window for testing.

Loop for the properties


Imports System.Reflection

 Dim t As Type = PartParam.GetType()
 Dim properties() As PropertyInfo = t.GetProperties()
 For Each Prop As PropertyInfo In properties
   Debug.Print("Name = " & Prop.Name & ", " & Prop.GetValue(PartParam, Nothing))
 Next



Class code:



<Serializable()> Public Class cParamGroup

    Private mCustomer As String
    Private mSONum As String
    Private mStyle As String
    Private mPressStroke As Single
    Private mPressType As String
    Private mLinkPressID As Single
    Private mRamUp As String
    Private mRamDist(19) As Single
    Private mPressLine As String
    Private mFileNumber As String
    Private mPartDesc As String
    Private mSpm As Single
    Private mCurrentFile As String
    Public AxisType(MaxAisType) As cAxisType
    Public DriveTrain(MaxAisType) As cDriveTrain
    Public GearBox(MaxAisType) As cGearBox
    Public AxisTypeParam(MaxAisType) As cAxisTypeParam
    'Public Motor(MaxAisType) As cMotor
    ' Public Motor(MaxAisType) As stMotor
    ''' <summary>
    ''' Initializes a new instance of the <see cref="cParamGroup"/> class.
    ''' Public Constructor
    ''' </summary>
    Public Sub New()

        For Loop1 As Integer = 0 To MaxAisType
            AxisType(Loop1) = New cAxisType
            DriveTrain(Loop1) = New cDriveTrain
            GearBox(Loop1) = New cGearBox
            AxisTypeParam(Loop1) = New cAxisTypeParam
            Motor(Loop1) = New cMotor
            
        Next Loop1

    End Sub
    Public Property CurrentFile As String
        Set(ByVal val As String)
            mCurrentFile = val
        End Set
        Get
            Return mCurrentFile
        End Get
    End Property

    ''' <summary>
    ''' Gets or sets the press line.
    ''' </summary>
    ''' <value>
    ''' The press line property.
    ''' </value>
    Public Property PressLine As String
        Set(ByVal val As String)
            mPressLine = val
        End Set
        Get
            Return mPressLine
        End Get
    End Property
    
End Class



thank you for any HELP .
Tom

Is This A Good Question/Topic? 0
  • +

Replies To: VB.net parameter count mismatch

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,197
  • Joined: 12-June 08

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 06:56 AM

What is 'MaxAisType'?
Was This Post Helpful? 1
  • +
  • -

#3 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 07:28 AM

MaxAxixType is a int and set to 7
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,197
  • Joined: 12-June 08

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 07:44 AM

Mkay.. Which line is it throwing the exception on?
Was This Post Helpful? 1
  • +
  • -

#5 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 09:31 AM

the exception error occurs on the for each loop shown
the exception is as follows: Exception thrown: 'System.Reflection.TargetParameterCountException' in mscorlib.dll
  For Each Prop As PropertyInfo In properties
     Debug.Print("Name = " & Prop.Name & ", " & Prop.GetValue(PartParam, Nothing))
  Next



I did figure out what was causing the error it was the following property that was a array. Code attached
It looks like when the for loop hits this property the reflection crashes out. When I remove the property RamDist I do not get the error. I also do not get the outputs for the other properties in the other class objects.

 Public Property RamDist(ByVal Idx As Integer) As Single
  Set(ByVal val As Single)
    mRamDist(Idx) = val
  End Set
  Get
    Return mRamDist(Idx)
  End Get
 End Property



Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,229
  • Joined: 12-December 12

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 09:44 AM

A complete guess would be that there must be a way, when iterating, to first check whether a property is a collection/array.
Was This Post Helpful? 1
  • +
  • -

#7 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: VB.net parameter count mismatch

Posted 06 September 2019 - 10:07 AM

I am thinking maybe checking the type and then maybe taking the array to a list before outputting the data
Was This Post Helpful? 0
  • +
  • -

#8 tneon1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-September 19

Re: VB.net parameter count mismatch

Posted 10 September 2019 - 01:34 PM

Thank You everyone for the questions and feedback
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1