locked
Newbe question (Linking to a Visual Basic class library) RRS feed

  • Question

  • User381773 posted

    I want to develope a mobile application for my company using Xamarin.

    I have got to grips with basics of Xamarin to the point at which and want to start using my companies standard routines for inter process communications (TCP/IP messages).

    All of these standard routines are part of a visual basic class library. I have added a reference to the class library under "project" and I can access the routines in C++ code (e.g. "Produce.Send_message (type, Message);"

    When I went to test to see is a message was sent, it initally said it could reference the visual basic runtime, add a NuGet package.

    So I did, I found the Microsoft.VisualBasic NuGet runtime and installed that.

    Now when I go to test the code, it just hangs and does nothing.

    And now I'm stuck.

    Before someone says just rewrite into C++ I should say there are a lot of routines coded in the class library that I will want to use (they are all tested and working exteremly well) so I really want to avoid rewriting it all into c++.

    Can any one help me?

    Wednesday, January 23, 2019 5:57 PM

Answers

  • User76049 posted

    @HaywardI said: Hi NMackay,

    Yes found that whilst trying to work out what was going on. However, it looked to me like it was giving me the ability to code VB.NET in a Xamarin project. I do not want or need that as I am happy to write the new code in c#.. However, I want to link to a class library DLL for all the standard routines (security, protocol, transmission, encryption, routing, auditing etc). I thought (obviously wrongly) when you built a class library it converted it into binary and could be executed by anything, but clearly there is a dependency on the VB runtime which I hadn't appreciated.

    I also found a post that said something about embedding the VB runtime into the class library itself , but I can't find any posts on how to do that in VS.

    Clint is kind of right in a humours way, but omits to consider the existing standard routines , built about 8 years ago are bullet proof and as the saying goes, if it aint broke, don't fix it. Hence I don't want to re-write and would like to find a way of bridging the c#/VB gap.

    All help appreciated.

    I hear you, I have nothing against VB.NET, I've written services, apps (even a digital video wall that supported live TV etc) in VB.NET in the past but of all the challenges of cross platform, I doubt you'll get what you want. Most want to see Forms improvements(Hotreload etc)/stability/better tooling.

    https://github.com/dotnet/vblang/issues/238

    I don't get any appetite within Microsoft to do this, I jumped to C# back in 2010 because I kind of saw VB.NET loosing traction, turned out to be a good decision.

    I'd suggest your going to have to port these rock solid VB.NET libs to C# & .NETStandard, I know that's not the answer you want to hear but it's the reality of your current tech stack.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 24, 2019 12:26 PM

All replies

  • User180523 posted

    Actually I would have said:

    Convert to C# (not C++) as they are both managed OOP .NET languages.

    Maybe it can be made to work. But nobody I know in the commercial software development industry uses/used VB in the last 20 years.

    Wait... You're saying 'VB' - but do you really mean Visual Basic, or at least Visual Basic .NET ? Because if its 30 year old VB that predates .NET, you're hosed and have to bring it up to date.

    Wednesday, January 23, 2019 6:18 PM
  • User381773 posted

    Hi ClintStLaurent,,

    My apologies. I should have said I want to avoid converting the code to C# as there is so much to convert.. And yes I mean VisualBasic.NET.

    Wednesday, January 23, 2019 6:24 PM
  • User76049 posted

    @HaywardI said: Hi ClintStLaurent,,

    My apologies. I should have said I want to avoid converting the code to C# as there is so much to convert.. And yes I mean VisualBasic.NET.

    There is very limited support for VB.NET

    https://docs.microsoft.com/en-us/xamarin/cross-platform/platform/visual-basic/xamarin-forms

    Wednesday, January 23, 2019 6:35 PM
  • User180523 posted

    @HaywardI said: I want to avoid converting the code to C#

    I want to avoid my in-laws for the holidays.

    We don't always get what we want.

    Wednesday, January 23, 2019 8:26 PM
  • User381773 posted

    Hi NMackay,

    Yes found that whilst trying to work out what was going on. However, it looked to me like it was giving me the ability to code VB.NET in a Xamarin project. I do not want or need that as I am happy to write the new code in c#.. However, I want to link to a class library DLL for all the standard routines (security, protocol, transmission, encryption, routing, auditing etc). I thought (obviously wrongly) when you built a class library it converted it into binary and could be executed by anything, but clearly there is a dependency on the VB runtime which I hadn't appreciated.

    I also found a post that said something about embedding the VB runtime into the class library itself , but I can't find any posts on how to do that in VS.

    Clint is kind of right in a humours way, but omits to consider the existing standard routines , built about 8 years ago are bullet proof and as the saying goes, if it aint broke, don't fix it. Hence I don't want to re-write and would like to find a way of bridging the c#/VB gap.

    All help appreciated.

    Thursday, January 24, 2019 10:19 AM
  • User76049 posted

    @HaywardI said: Hi NMackay,

    Yes found that whilst trying to work out what was going on. However, it looked to me like it was giving me the ability to code VB.NET in a Xamarin project. I do not want or need that as I am happy to write the new code in c#.. However, I want to link to a class library DLL for all the standard routines (security, protocol, transmission, encryption, routing, auditing etc). I thought (obviously wrongly) when you built a class library it converted it into binary and could be executed by anything, but clearly there is a dependency on the VB runtime which I hadn't appreciated.

    I also found a post that said something about embedding the VB runtime into the class library itself , but I can't find any posts on how to do that in VS.

    Clint is kind of right in a humours way, but omits to consider the existing standard routines , built about 8 years ago are bullet proof and as the saying goes, if it aint broke, don't fix it. Hence I don't want to re-write and would like to find a way of bridging the c#/VB gap.

    All help appreciated.

    I hear you, I have nothing against VB.NET, I've written services, apps (even a digital video wall that supported live TV etc) in VB.NET in the past but of all the challenges of cross platform, I doubt you'll get what you want. Most want to see Forms improvements(Hotreload etc)/stability/better tooling.

    https://github.com/dotnet/vblang/issues/238

    I don't get any appetite within Microsoft to do this, I jumped to C# back in 2010 because I kind of saw VB.NET loosing traction, turned out to be a good decision.

    I'd suggest your going to have to port these rock solid VB.NET libs to C# & .NETStandard, I know that's not the answer you want to hear but it's the reality of your current tech stack.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, January 24, 2019 12:26 PM
  • User381773 posted

    NMackey,

    I hear you too, so decided to convert my routines into C#.

    Conversion of first routine surprisingly simple, even if syntax is a little frustrating ;-) But then I started programming Basic on PDP11's (Yes, I am that old).

    Thanks for your help. Iain

    Monday, January 28, 2019 1:29 PM
  • User381773 posted

    NMackey/All

    I just tested the new routine for the first time and had a curious result I thought I would share.

    As above I converted my first routine to C# and began testing. It didn't work and just hung as per the results I got when I tested against the VB.NET class library. Discovered I could not debug when testing using a hand set so decided to write a C# console program to test against calling the same class library in C# and it worked first time. That got me thinking! Discovered my wifi security on my handset was blocking the TCP/IP message. Changed my WIFI security and everything work ok. But this isn't the important thing.

    I then thought if I had the same symptom with the C# class library, what if I switched back to my VB.NET class library.

    Holy crap when I ran using the VB.NET library it also WORKED.

    So in summary, you can link a Xamarin C# program to a visual basic class library. All you need to do is add the Nuget Visual Basic runtime package and off you go.

    That said I will convert my common routines (sorry methods) into C# if only for the practice :-) Iain

    Monday, January 28, 2019 1:47 PM
  • User180523 posted

    @HaywardI said: Conversion of first routine surprisingly simple, even if syntax is a little frustrating ;-) But then I started programming Basic on PDP11's (Yes, I am that old).

    Not quite at the PDP11 era here... First computer was a Timex-Sinclair. Then a Commodore PET... then VIC20... Then C-64

    into C#. {...} even if syntax is a little frustrating ;-) Its a change over. Then one day you'll realize the C# looks normal and the VB seems odd - and wonder when that mental switch happened.

    Monday, January 28, 2019 2:06 PM