1

I have a vb.net app that I want to use to make a call to a c# function that has a collection of class objects as a parameter. I have tried constructing a class with the same structure in the vb.net app and declaring a list of objects populating them with data and passing these into the c# class but I get a conversation error

List(of AddressClass) cannot be converted to List(Of AddressClass)

Is it possible to achieve this? If so, then how?

The function is:

public static string callMain(List<AddressClass[]> Addresses)
{
    // code.......
}
3
  • The AddressClass in vb need to be the same as the c# one, do not create your own. Commented Aug 9, 2018 at 16:08
  • Do you mean that I should copy the class across from the c# project to the vb.net app? Commented Aug 9, 2018 at 16:10
  • @joebohen, you just add the reference to the project, and then create an object of the class just like you do with other vb classes. You can forget which language that library was written in. Commented Aug 9, 2018 at 16:19

1 Answer 1

1

You don't need to duplicate any classes. The whole beauty of the .NET Framework is the interchangeability of the languages. Just use the AddressClass definition which is used by the C# function. If the C# project is references in the VB one then your VB Code will recognise it.

So e.g. if the C# project's namespace is My.CSharp.Project then in VB you can just Dim list As new List(Of My.CSharp.Project.AddressClass).

Basically just treat the C# classes just like any other library. You don't know or care what language the System.IO classes are written in, do you? You just use them. The same goes for your C# project. In fact if you'd compiled your C# project to a DLL and manually imported it into your VB.NET project, you wouldn't even necessarily know it was a C# project - all you've got at that time is a compiled binary file.

Sign up to request clarification or add additional context in comments.

2 Comments

I have excluded the duplicate class and the c# class is recognised but I am getting exactly the same error in my vb.net app!
Sorry about that, the call is working now thanks to everyone for there comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.