0

I have an .NET Core 2.0 Web API that, obviously is built in C#. I have a method that calls a void function from a VB dll and when I run the program this function call throws the following exception.

System.MissingMethodException: Method not found: 'System.Object Microsoft.VisualBasic.Interaction.IIf(Boolean, System.Object, System.Object)'

I have registered the dll on GAC, I have referenced the project itself other than the .dll file, and even so, Visual Studio wouldn't let me even debug it.

Using Visual Studio 2017, .NET Core 2.0 Framework.

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
Longshadow
  • 109
  • 1
  • 1
  • 8

3 Answers3

2

In short, there is no way to integrate a VB dll to a .NET Core. Most of the native VB functions don't work. My advice is to translate the dll to c#.

Longshadow
  • 109
  • 1
  • 1
  • 8
0

Everything in .NET Core is NuGet packages now. Just add the Microsoft.VisualBasic package to your project from NuGet and you should be good to go.

Mind you, it looks like you're using the Microsoft.VisualBasic.Interaction.IIf method. There is an equivalent to that build right into the C# language: the ? operator. Use it like this:

var myVariable = something == "A" ? "Equals A" : "Doesn't equal A"
Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • I have downloaded the NuGet package of VisualBasic and alas, it still did not work. Apparently, .NET Core does not support most of VB functions. I am currently trying to get a lib called CoreFX do work, as it does have a VisualBasic lib and the functions i need (i. e. iif(), InStr and so on). But Thank you for the package heads up. I did not know about that. – Longshadow Dec 18 '18 at 16:41
  • The source code is available in GitHub now, so you could just copy the code (and translate to C#) for the methods you want. For example, the `IIf` method is [here](https://github.com/dotnet/corefx/blob/master/src/Microsoft.VisualBasic/src/Microsoft/VisualBasic/Interaction.vb) – Gabriel Luci Dec 18 '18 at 17:00
  • Although that specific one (`IIf`) is kind of pointless in C# because of the [`?` operator](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator). You can just do `something == somethingelse ? "this" : "that"` – Gabriel Luci Dec 18 '18 at 17:07
  • I ended up translating the whole of the dll to C#. – Longshadow Dec 21 '18 at 13:25
0

Convert the IIf to If.

Example: IIF(SomeCondition, "A", "B") to IF(SomeCondition, "A", "B")

Reference: VB.NET Ternary Operator

spottedmahn
  • 14,823
  • 13
  • 108
  • 178