14

I am attempting to utilize some of the static classes in the Microsoft.VisualBasic name space in a .Net Standard 2.0 Class library (the Financial.Rate function specifically.) This is a C# project and the library contains various financial functions and calculations. I know that simply adding the using Microsoft.VisualBasic; is not enough since I need to reference the actual dll. But I am not sure how to do this in a .net Standard Class library.

I have tried adding the NuGet Package Microsoft.VisualBasic to the library but that would not allow me to access the static classes that I need. I am rather new to .Net so I am confused about how to properly reference the assembly. All examples that I can find involve some of the older .net Framework libraries and not .net Standard. Below is a link to a screen shot of the reference manager, Solution Explorer and using statements are shown below.

Reference Manager Screen Shot

Solution Explorer

Using Statements & Implementation

Any help or suggestions would be greatly appreciated.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Luke Bethay
  • 143
  • 2
  • 8
  • were you able to use VisualBasic finacial libraries on net standard? – Luis Palacios Mar 12 '20 at 20:50
  • @LuisPalaicos There is no way to import them directly. What you can do is use something like [dotPeak](https://www.jetbrains.com/decompiler/) and decompile the VB libraries into C#. I've done this successfully before. – Luke Bethay Apr 13 '20 at 14:05
  • 1
    What a massive disappointment that Microsoft isn't supporting a migration path for the core APIs of one of its pillar languages. No `Microsoft.VisualBasic` support in .NET Standard means no sharing existing VB libraries who use VB APIs between .NET Framework and Core+ without massive rewrites. Supporting it in .NET Core proves they have the cross-platform implementation and could port it into `Microsoft.Windows.Compatibility`, but they just didn't for some reason. Pretty large omission if you ask me. – Jacob Stamm Jan 26 '22 at 13:50

1 Answers1

6

Add a NuGet package Microsoft.VisualBasic via NuGet Package Manager,

https://www.nuget.org/packages/Microsoft.VisualBasic/

Or simply modify the project file to add an equivalent PackageReference.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • 1
    When I add the NuGet Package "Microsoft.VisualBasic" and then add the using statement for Microsoft.VisualBasic, static methods such as the financial.rate still do not exist in my current context. I've added screen shots of my solution explorer and my using statements above to show what I am talking about. Am I implementing them wrong or am I missing something? – Luke Bethay Feb 21 '18 at 12:03
  • 1
    That Nuget package is pretty useless. Odd, you'd wonder if there are any vb.net programmers out there that use netstandard. It doesn't get better in a vb.net netstandard project, looks like they just haven't gotten the job done yet or chose to forego vb.net support on unix platforms. – Hans Passant Feb 21 '18 at 12:14
  • @LukeBethay I answered your question, by showing the right way to add references, but I cannot help bring `Financial` class to .NET Standard/.NET Core, as Microsoft currently only plans to ship it on .NET Framework, https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.financial?view=netframework-4.7.1#Applies_to If you want to see a change, raise a new issue on GitHub. Previous issues like [this one](https://github.com/dotnet/corefx/issues/14300) are still open. – Lex Li Feb 21 '18 at 14:02
  • @LexLi I see, I will try to find a workaround. Thanks for providing the documentation. – Luke Bethay Feb 21 '18 at 14:13
  • were you finally able to find a workaround @LukeBethay? I'm running into the same issue :/ – Luis Palacios Mar 12 '20 at 20:50