简体   繁体   English

C#DLL运行时错误 - 构建,运行,但在尝试使用DLL函数时抛出未处理的异常

[英]C# DLL run-time error - builds, runs, but throws unhandled exception upon trying to use DLL functions

I am trying to compile the example project shown here for C#. 我正在尝试编译此处显示的C#示例项目。 It had to be converted to VS2010, but that worked fine. 它必须转换为VS2010,但工作正常。 It builds, runs, but then dies when it tries to access a DLL function. 它构建,运行,但在尝试访问DLL函数时死亡。

I made a series of images to show my steps. 我制作了一系列图片来展示我的步骤。 As you can see, the device I designed is attached and correctly configured, but I really don't think that has anything to do with the issue. 如您所见,我设计的设备已连接并正确配置,但我真的认为这与该问题无关。 Inside the Form1.cs file, the following comment explains how to use the DLL: 在Form1.cs文件中,以下注释说明了如何使用DLL:

/*
PLEASE NOTE
You must add a reference to the FTChipIDNet.dll in order to use this sample
To do this:
1. Click on Solution explorer tab.
2. Right click the References tree.
3. Choose Add Reference option.
4. Browse to the FTChipIDNet.dll (as a personal preference I place this in my bin directory)
5. Click OK
*/

I followed the instructions shown above and the undefined reference to the namespace FTChipID was fixed. 我按照上面显示的说明修改了名称空间FTChipID的未定义引用。 I also manually checked the Object Browser to be sure the GetNumDevices function exists and it does. 我还手动检查了对象浏览器,以确保GetNumDevices函数存在并且确实存在。

Clicking the button produces this error: 单击该按钮会产生以下错误:

DLLNotFoundException was unhandled: DLLNotFoundException未处理:

Unable to load DLL 'FTChipID.dll': The specified module could not be found. 无法加载DLL“FTChipID.dll”:找不到指定的模块。 (Exception from HRESULT: 0x8007007E) (来自HRESULT的异常:0x8007007E)

at this line of code: 在这行代码:

FTChipID.ChipID.GetNumDevices(ref numDevices);

Now, you may be thinking "the error says it needs FTChipID.dll, not FTChipIDNet.dll." 现在,你可能会想“错误说它需要FTChipID.dll,而不是FTChipIDNet.dll。” I'm wondering the same thing. 我想知道同样的事情。 I have FTChipID.dll along with a .lib and .h file, but I don't know how to use them or where they need to be in order for this program to find them. 我有FTChipID.dll以及.lib和.h文件,但我不知道如何使用它们或它们需要在哪里才能让这个程序找到它们。 I tried adding a reference to FTChipID.dll, but VS2010 said 我尝试添加对FTChipID.dll的引用,但VS2010说

A reference to ...\\FTChipID.dll could not be added. 无法添加对... \\ FTChipID.dll的引用。 Please make sure that the file is accessible, and that it is a valid assembly or COM component. 请确保该文件是可访问的,并且它是有效的程序集或COM组件。

I don't know what that means either. 我也不知道这意味着什么。 Any ideas? 有任何想法吗? Thanks in advance. 提前致谢。

I built the FTDI sample program "CSChipID" in VS2013 using a build to "Any CPU". 我使用构建到“任何CPU”在VS2013中构建了FTDI示例程序“CSChipID”。 The two DLL files "FTChipID.dll" and "FTChipIDNet.dll" were copied to the bin directory, but I continued to get errors when the first DLL function was called, "FTChipID.ChipID.GetNumDevices(ref numDevices);" 两个DLL文件“FTChipID.dll”和“FTChipIDNet.dll”被复制到bin目录,但是当第一个DLL函数被调用时,我继续收到错误,“FTChipID.ChipID.GetNumDevices(ref numDevices);” The fix is change the build to "x86" as follows. 修复程序将构建更改为“x86”,如下所示。

Build - Configuration Manager Active Solution Platform - "x86" Note: If "x86" is not available, select -New...- to select "x86". 构建 - 配置管理器活动解决方案平台 - “x86”注意:如果“x86”不可用,请选择-New ...-以选择“x86”。

FTChipIDNet.dll is a wrapper for the FTChipID.dll, so you need to add the reference to your solution (as you did above) and then copy the FTChipID.dll to the bin folder there FTChipIDNet.dll will be located. FTChipIDNet.dll是FTChipID.dll的包装器,因此您需要添加对您的解决方案的引用(如上所述),然后将FTChipID.dll复制到将存在FTChipIDNet.dll的bin文件夹中。

Both dll's should be located in your solution's bin folder to operate and should not be located in windows\\system32. 这两个dll都应位于解决方案的bin文件夹中以进行操作,不应位于windows \\ system32中。

It sounds like there are multiple .dll's: both FTChipIDNet.dll (the one you interface to), and FTChipID.dll (the one with the actual, non-COM, non-.Net functionality). 听起来有多个 .dll:FTChipIDNet.dll(你接口的那个)和FTChipID.dll(具有实际的非COM,非.Net功能的那个)。 You need both. 你需要两者。

SUGGESTION: Copy both to your \\windows\\system32 directory 建议:将两者都复制到\\ windows \\ system32目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c# 中的运行时错误 - mscorlib.dll 中发生类型为“System.FormatException”的未处理异常 - Run-time error in c# - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll 未处理的异常C#dll - unhandled exception c# dll C ++ dll的C#包装器; “运行时检查失败#0 - ESP的值未在函数调用中正确保存。”错误 - C# wrapper of c++ dll; “Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.” error List.Sort()引发mscorlib.dll中发生类型为'System.InvalidOperationException'的未处理异常-C# - List.Sort() throws An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll - C# 尝试在运行时编译中引用注册表 dll - Trying to reference registry dll in run-time compilation 如何在C#中正确多线程运行时调用的DLL - How to Correctly Multi-Thread a DLL Called at Run-Time in C# C#引发未处理的异常错误 - C# throws Unhandled exception error 从C#程序调用c ++ DLL,未处理的异常 - Calling c++ DLL from C# Program, unhandled exception 尝试在C ++中加载COM包装的DLL时出现未处理的异常 - Unhandled exception when trying to load a COM wrapped DLL in C++ C#错误:System.Drawing.dll中发生了类型为'System.OutOfMemoryException'的未处理异常 - C# Error: An unhandled exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM