How to read the returned complex object values when calling a method by reflection using 'Invoke' in VB.net - vb.net

As you can see in the picture I see the return values from the call but I cannot use them.
How can I convert the return object to something else. This function is dynamic so I cannot use a reference object for this class.

Thank you!
I managed to read the object by using this
Dim oResults As Object = oMethod.Invoke(oUbCustomerService, oParameterValues)
For Each oResult in oResults
Dim oFieldInfoList() As FieldInfo = oResult.GetType().GetFields
dim strValue as String = oFieldInfoList(n).GetValue(oResult)
...
Next

Related

Convert Double value to Array in vb.net

I have vb.net application which fetches data from the excel and perform some operation.
I am using excel object Range to get the values from excel.
Below is the line of code I am using,
xlsRangetrans = xlsWorkbook.Worksheets(SHEET_1).Range("Range1")
Dim transArray(,) As Object = xlsRangetrans.Value
The above code runs successfully if I have more than one values in the Range1.
But if I have only one value I am getting error.
Eg: xlsRangetras.value has "123.0,124.0,nothing,nothing" as System.Array which runs successfully
But if xlsRangetras.value has "123.0" as Double, it gives me error.
How to convert Double value to Array in my case.
Please help.
Dim helper As Object = xlsRangetrans.Value
Dim transArray(,) As Object = _
If(TypeOf helper Is Object(,), helper, {{DirectCast(helper, Object)}})
Update
Obviously the If operator didn't exist in older .NET versions. In this case that piece of code might help.
Dim helper As Object = xlsRangetrans.Value
Dim transArray(,) As Object
If TypeOf helper Is Object(,) Then
transArray = helper
Else
transArray = {{DirectCast(helper, Object)}}
End If

VB Web Service call error Object reference not set

Hey all I am trying to figure out why I am getting the following error:
Object reference not set to an instance of an object.
on line 2 of code:
1. Dim HTPCws As HTPCWS.ServiceVB
2. Dim returned As String = HTPCws.DisplayMessageVB(what2send)
When I know what2send does have a value to send....
The Web Service code is this:
<WebMethod()> Public Function DisplayMessageVB(ByVal beingSent As String) As String
_strfromws = beingSent
Return "DONE"
End Function
What could I be forgetting?
HTPCws has not been instantiated. Change the code to:
Dim HTPCws = New HTPCWS.ServiceVB()
Dim returned As String = HTPCws.DisplayMessageVB(what2send)
Dim HTPCws As HTPCWS.ServiceVB declares a variable but does not assign it an object. Also the naming is a bit confusing. Better:
Dim service = New HTPCWS.ServiceVB()
Dim returned As String = service.DisplayMessageVB(what2send)

Object Reference casting vb.net

I have no idea on how to cast an object that type was 'Object' to a user defined class type.
I have a private instance variable:
Private studyType as Object
What i need to do is to instantiate this object from an event handling method. And no, not to instance new Object().
Basically it would look like this:
studyType = new VCEOnly()
However, I am only allowed to use the Object class subs and functions as the type was defined as Object. So i need to cast it to VCEOnly class type so i can access its subs and functions.
Basically, studyType needs to be casted from Object to VCEOnly. I am not allowed to pre-define studyType as VCEOnly when declared.
you can also use:
dim studyType as Object = new VCEOnly()
...
dim studyTypeVCE as VCEOnly = nothing
if trycast(studytype,VCEOnly) IsNot Nothing then
studyTypeVCE = DirectCast(studytype,VCEOnly)
'... do your thing
end if
the if statement checks if the object can be casted to the wanted type and if so variable of type VCEOnly will be filled in with a cast of studytype.
Use CType to cast an object from one type to another
Something like this should do it:
Dim studyType as Object
Dim studyTypeVCE as New VCEOnly
studyTypeVCE = Ctype(studyType,VCEOnly)
or you can just do this:
With CType(studyType, VCEOnly)
.SomeVCEOnlyProperty = "SomeValue"
End With

Unable to solve error "reference to a non-shared member requires an object reference. vb.net "

I have the following code
Case "Formula_MDX"
Dim cubeid As String = Request("intCubeId")
Dim strDimCode As String = Request("strDimCode")
Dim strMdxFormula As String = Request("strMdxFormula")
Dim result As String
result = HostAnalytics.HostAnalyzer.HostAnalyzer.setSubstituteVarMDXType(cubeid, strDimCode, strMdxFormula)
Case Else
Response.Write("Invalid call")
End Select
that vb method returns data of type string.
I declared the result of the typed string. but it is showing on that vb method like
"reference to a non-shared member requires an object reference"
How to solve this? Did I make any other mistakes in this code?
Make an object of that type, and invoke the method on that
Dim ha As New HostAnalytics.HostAnalyzer.HostAnalyzer() 'Edit, need New
result = ha.setSubstituteVarMDXType(cubeid, strDimCode, strMdxFormula)

VB6 COM returns ADODB.Recordset in byRef Variant. How to retrieve in C#?

I'm trying to call this COM method:
Public Function DoSomething(ByRef StringStuff As Variant, **ByRef Out_Data As Variant**) As Boolean
Out_Data gets defined and populated in the method body as an ADODB.Recordset (2.6).
I've tried several different ways I can think of, but still can't seem to get that recordset object out, or in for that matter.
Any ideas?
Thanks...
Can you call it using ref or out?
Object StringStuff = "Hello Word";
Object Out_Data = null;
DoSomething(ref StringStuff, ref Out_Data);
// or
DoSomething(out StringStuff, out Out_Data);
//I haven't use ADODB in a long while so convert this to whatever type is necessary
ADODB.Recordset ar = (ADODB.Recordset)Out_Data;