我将我的项目引用到从硬件供应商处获得的外部DLL,并且遇到此错误:
Exception thrown: 'System.FormatException' in mscorlib.dll
Exception thrown: 'System.FormatException' in mscorlib.dll
Exception thrown: 'System.FormatException' in Microsoft.VisualBasic.dll
Exception thrown: 'System.InvalidCastException' in Microsoft.VisualBasic.dll
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "8010001D" to type 'Integer' is not valid.
但是,在Visual Studio 2017中没有编译错误,只有运行时崩溃。一位同事可以在Visual Studio 2012中对其进行调试。我试图将目标平台从.NET 2.0更改为.NET 4.5,但仍然失败。
这是源代码。目前,我只是想看看引用是否正确,但IMO应该没有任何问题。
class Program
{
static void Main(string[] args)
{
MyKad reader = new MyKad(); //the app breaks here. MyKad() is a dll object
Console.WriteLine("Testing app starts..");
if(reader.Connect())
{
Console.WriteLine("Obj creation succeed");
}
else
{
Console.WriteLine("Obj creation failed");
}
}
}
MyKad()
来自dll。我可以看到方法信息,但看不到实际的代码。我是否错过了项目配置中的任何旧设置?
下面是调用堆栈
Microsoft.VisualBasic.dll!Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger( Value) Line 788 + 0x84 bytes Basic
CSMyKad.dll!CSMyKad.MyKad.UserControl_Initialize() + 0x73 bytes
CSMyKad.dll!CSMyKad.MyKad.MyKad() + 0x11e bytes
MyKadLib.exe!MyKadLib.Program.Main(string[] args) Line 16 C#