dll中引发System.MissingMethodException的方法:未找到方法

时间:2018-12-17 13:43:04

标签: c# vb.net dll .net-core .net-core-2.0

我有一个.NET Core 2.0 Web API,显然是用C#构建的。我有一个从VB dll调用void函数的方法,当我运行程序时,此函数调用将引发以下异常。

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

我已经在GAC上注册了该dll,我引用了项目本身,而不是.dll文件,即使这样,Visual Studio也不允许我调试它。

使用Visual Studio 2017,.NET Core 2.0框架。

3 个答案:

答案 0 :(得分:1)

简而言之,无法将VB dll集成到.NET Core。大多数本机VB功能不起作用。我的建议是将dll转换为c#。

答案 1 :(得分:0)

.NET Core中的所有内容现在都是NuGet软件包。只需将Microsoft.VisualBasic软件包从NuGet中添加到您的项目中,您就可以开始使用了。

请介意,您似乎正在使用Microsoft.VisualBasic.Interaction.IIf方法。 C#语言中有一个等效于该构建的版本:the ? operator。像这样使用它:

#include <vector>
#include <random>
#include <algorithm>
#include <iterator>

int main() {
  std::vector<double> x;
  const int n = 10;

  std::default_random_engine gen(std::random_device{}());
  std::uniform_real_distribution<double> dist(0.0, 1.0);
  std::generate_n(std::back_inserter(x), n, [&]{ return dist(gen); });
}

答案 2 :(得分:0)

IIf转换为If

示例:从IIF(SomeCondition, "A", "B")IF(SomeCondition, "A", "B")

参考:VB.NET Ternary Operator

相关问题