Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 104109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:13:47+00:00 2026-05-11T01:13:47+00:00

I’ve some classes defined in a dll file. These are in the form of

  • 0

I’ve some classes defined in a dll file. These are in the form of com api.

I’m trying to create an object of one of the class dynamically and than setting some property of that object.

When I set the property manually, it works, but when I try to invoke the same using reflection it gives the error that

Object does not match target type.

Following is my code

Private Sub SetObjectValue(ByVal SelectedObject As SAPbobsCOM.BoObjectTypes, ByVal ClassName As String, ByVal FieldName As String, ByVal SetValue As String, ByVal KeyValue As String)     Dim oObject As Object      Dim myAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom("interop.sapbobscom.dll")     Dim myType As Type = myAssembly.GetType(ClassName)      Dim myMember() As MemberInfo = myType.GetMember(FieldName)     Dim myProperty As PropertyInfo = CType(myMember(0), PropertyInfo)     Dim myMethod As MethodInfo = myProperty.GetSetMethod       oObject = oCompany.GetBusinessObject(SelectedObject)      oObject.GetByKey(KeyValue)      myProperty.SetValue(oObject, CDbl(SetValue), Nothing) End Sub 

It gives the error when SetValue method is called. Instead, if I use this like following it works fine:

oObject.CreditLimit = 129 oObject.Update 

Where CreditLimit is a property of the given class, and update is a method which I have to call, after the value is set, so that the value in underlying database is updated.

Similarly GetByKey is used to retrieve the value of the object from the underlying database, where the value of the primary key field has to be passed.

Since there are multiple classes and each class has lots of different properties, therefore calling them dynamically will help a lot.

Thanks Rahul Jain

Just tried doing what casper has suggested here. It gives an error saying – Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

Rahul

Its done. Instead of vbSet, I used vbLet and it completed successfully.

Thanks Rahul

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:13:48+00:00Added an answer on May 11, 2026 at 1:13 am

    I am kind of curious why you are doing this, as VB will do all of it for you. You simply have to declare as type object and then make the call, or are you using an option (I believe it is strict?) which prevents you from letting the compiler emit the reflection code for late-bound calls?

    If you need to take a parameter, you should be able to use CallByName as well:

    Private Sub SetObjectValue(ByVal SelectedObject As SAPbobsCOM.BoObjectTypes, ByVal ClassName As String, ByVal FieldName As String, ByVal SetValue As String, ByVal KeyValue As String)     Dim oObject As Object    oObject = oCompany.GetBusinessObject(SelectedObject)      oObject.GetByKey(KeyValue)      CallByName(oObject, FieldName, vbSet, CDbl(SetValue)) End Sub 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
i got an object with contents of html markup in it, for example: string
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
i want to parse a xhtml file and display in UITableView. what is the
I've got a string that has curly quotes in it. I'd like to replace
I have a JSP page retrieving data and when single or double quotes are
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.