Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to talk to an instrument controller in C# through a .NET VB DLL provided by the manufacturer in an example project. The VB code works flawlessly. When I attach the DLL as a reference to my C# project a key property is missing. All the other properties and methods appear as expected. The methods that do appear work in the C# project. In the VB Object Browser the property is defined as follows:

VB
ModbusTransaction‎(Byte‎) As Object

which references the code:

VB
Public ReadOnly Property ModbusTransaction(ByVal CommandType As Byte)
    Get
        Call _ModbusTransaction(CommandType)
        Return _TransactionSuccess
    End Get
End Property


This property is used as a method in the example code so I do not know why it is not declared as such. My problem is that I cannot execute this or know how to find it from C#. I am using VS 2013 if that makes a difference.

Thanks for any help,
SMW

What I have tried:

I have tried methods from the DLL in my C# project and the ones that do not require the missing property (method) work properly.
Posted
Updated 15-Jul-16 11:23am
Comments
E.F. Nijboer 15-Jul-16 17:19pm    
Make sure the platform of both vb.net and c# projects match (so they have matching language runtimes). Also check if they still default to "anycpu". Also, not sure the ByVal might cause the problem. Maybe try it without to see if it has any effect.

1 solution

You didn't give the VB Property code a return type.
VB
Public ReadOnly Property ModbusTransaction(ByVal CommandType As Byte) As ????
    Get
        _ModbusTransaction(CommandType)
        Return _TransactionSucess           '<----Where is this value coming from?
   End Get


Or should that property really be a Function??
VB
Public Function ModbusTransaction(ByVal CommandType As Byte) As ????
    return _ModbusTransaction(CommandType)
End Function
 
Share this answer
 
Comments
Stephen Wickland 15-Jul-16 19:18pm    
Hi Dave, Sorry I was not clear. I did not modify the DLL source code as it works in the VB example. I am also curious why "ModbusTransaction" is a property in the DLL and not a function. Your comments in the code make sense but my VB skills are too poor to give you a good answer. My question is why might a parameter of type object in VB not appear in a C# Object Browser. I suspect that C# somehow doesn't know the type from the info in the DLL.
Thanks,
SMW
Dave Kreskowiak 17-Jul-16 17:23pm    
After trying this out, that VB "Property" will not show up in C# as a property. It'll show up as a method with the name "get_ModbusTransaction".

As for why it's disappearing from Object Browser, I haven't been able to duplicate the behavior at all.
Stephen Wickland 18-Jul-16 12:52pm    
Thanks, I missed the change in name and type. By disappeared I meant the property disappeared. It reappeared as a method in C# with a slightly different name which makes more sense anyway. Thanks for your efforts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900