应用程序在 InitializeComponent() 中崩溃
首先,我使用 Visual Studio 2010、Measurement Studio 2010 插件、C# 和 .NET 4.0。
我的应用程序从 USB 设备接收数据,并使用 WaveformPlot()
[这是Measurement Studio 的一部分] 绘制数据图表。我能够在调试和发布模式下正常运行该应用程序,甚至可以直接使用开发计算机上 bin
文件夹中的 EXE 文件正常运行该应用程序。
但是,我根本无法在另一台计算机上运行它。我使用 ClickOnce 创建安装文件和文件夹,然后从我的开发计算机到客户端计算机。然后运行安装文件,ClickOnce 下载 .NET(如果尚未安装),然后打开应用程序。该应用程序显示了我的初始对话框,要求我从许多可用的 COM 端口中选择一个。执行此操作后,我的代码将执行 InitializeComponent()
,之后主窗体应该会显示。
在初始框之后主窗体不会打开。使用 Debug.WriteLine 语句,我已经能够将范围缩小到
this.waveformPlot = new NationalInstruments.UI.WaveformPlot();
“It crashes here”。它没有向我显示任何错误消息或任何内容。它在我的开发计算机上运行良好,但在其他计算机上运行不佳。我包含了 National Instruments DLL 文件,其他 National Instruments 组件也已初始化良好。只是这个没有。该应用程序会在 Windows 任务管理器中显示一段时间,然后在大约 10 秒后消失。
我应该怎么办?
更新 1
在阅读 StackOverflow 上的另一个不相关问题后,我意识到我可以将 Application.run
和 form1 mainform = new form1() 在 try-catch 块中。
System.TypeInitializationException:“NationalInstruments.UI.Internal.WaveformPlotElement”的类型初始值设定项引发异常。 --> System.IO.FileNotFoundException:无法加载文件或程序集“NationalInstruments.Common.Native.dll”或其依赖项之一。找不到指定的模块。
因为我现在至少知道这是一个异常,所以我将对其进行处理,尝试找出缺少哪个 DLL 以及原因,并更新此问题。
更新 2
我检查了发布文件夹中的应用程序文件,它确实包含“NationalInstruments.Common.Native.dll”。我不知道为什么它无法加载它。
更新 3
我在客户端计算机上运行 Fusion Log Viewer,看到 NationalInstruments.Common.Native.dll
已成功加载。但是,调试异常消息仍然显示如OP所示,
无法加载文件或程序集“NationalInstruments.Common.Native.dll”或其依赖项之一”
Fuslog 查看器显示我在客户端计算机上检查了所有程序集,但 National Instruments DLL 文件中有一行显示。其中“GAC 查找失败”,而其他程序集则没有
显示我使用 Debug.writeLine 打印出的异常。这表明 NationalInstruments.Common.Native.dll< /code> 或其依赖项之一无法加载,
。
我尝试添加对项目的引用,使用反编译器检查引用,使用其他安装程序(ClickOnce 除外),但似乎都没有 :(
更新 4
我昨天才发现该应用程序在 64 位系统上安装并运行良好。我之前尝试过的两台计算机是 32 位 Windows 7 系统。 我想看看这是否能以某种方式帮助我。 该应用程序是在我的 64 位 Windows 7 开发笔记本电脑上编译的。项目属性下“构建”中的“平台”下拉菜单显示“活动(x86)”,并且我将“任何 CPU”作为平台目标。
First off, I'm using Visual Studio 2010, Measurement Studio 2010 plugin, C# and .NET 4.0.
My application receives data from a USB device and graphs the data using a WaveformPlot()
[which is a part of Measurement Studio]. I'm able to run the application fine in debug and release modes and even run it fine directly using the EXE file in the bin
folders, on the development computer.
However, I am simply unable to run it in a different computer. I'm using ClickOnce to create an install file and folders, and I copy the publish folder from my development computer to the client computer. I then run the install file, ClickOnce downloads .NET (if it's not already installed) and then opens the application. The application shows my initial dialog asking me to choose a COM port from the many available. Once I do this, my code goes through the InitializeComponent()
after which the main form is supposed to show up.
The main form doesn't open up after the initial box. Using Debug.WriteLine
statements, I've been able to narrow it down to
this.waveformPlot = new NationalInstruments.UI.WaveformPlot();
It crashes here. It doesn't show me any error message or anything. It works fine on my development computer, just not on other computers. I included the National Instruments DLL files and other National Instruments components are initialized fine. It's just this one that doesn't. The application shows up in the Windows Task Manager for a while and then just vanishes after like 10 seconds.
What should I do?
Update 1
After reading another unrelated question on Stack Overflow, I realized that I could put the Application.run
and the form1 mainform = new form1()
in a try-catch block.
System.TypeInitializationException: The type initializer for 'NationalInstruments.UI.Internal.WaveformPlotElement' threw and exception. --> System.IO.FileNotFoundException: Could not load file or assembly 'NationalInstruments.Common.Native.dll' or one of its dependencies. The specified module could not be found.
Since I at least know it's an exception now, I'll work on it, try to figure out which DLL is missing and why, and update this question.
Update 2
I checked the application files that are in the publish folder, and it does include the 'NationalInstruments.Common.Native.dll'. I have no idea why it can't load it.
Update 3
I ran Fusion Log Viewer on the client computer and saw that the NationalInstruments.Common.Native.dll
was loaded succesfully. But still, the debug exception message shows up as shown in the OP,
Could not load file or assembly 'NationalInstruments.Common.Native.dll' or one of its dependencies"
Screenshot of what the Fuslogvw.exe shows
Fuslog Viewer shows that all the assemblies have been loaded successfully. I checked on the client computer. Although, the National Instruments DLL files have a line which says "GAC lookup unsuccessful" in them while the other assemblies don't.
DebugViewer displays the exception that I print out using Debug.writeLine
. This shows that the NationalInstruments.Common.Native.dll
or one of its dependencies could not be loaded.
I am very confused.
I tried adding references to the project, using a decompiler to check references, using other install programs (other than ClickOnce) and none of them seem to be getting me anywhere. :(
Update 4
I just found out yesterday that the application was installing and running fine on 64-bit systems. The two computers I tried it on before were 32-bit Windows 7 systems.
I am looking to see if that could help me somehow.
The application was compiled on my 64-bit Windows 7 development laptop. The 'Platform' drop down menu in 'Build' under project properties shows 'Active (x86) and I have 'Any CPU' as the platform target.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在花了很多时间在这个问题上之后,我与 National Instruments 的某人交谈,他帮助我解决了我遇到的问题。我之前注意到,通过检查
mstudiocommon.2010.msm
的模块依赖项,它 (mstudiocommon.2010.msm
) 正在寻找vs100_crt_x86.msm
文件,但安装程序已检测到(并添加)了vs90_crt_x86.msm
(在安装程序项目的“检测到的依赖项”)。右键单击安装程序项目并手动添加 VS100 .msm 文件修复了我遇到的问题。下面是我可以看到的
mstudiocommon
和mstudioui
合并模块的模块依赖关系的屏幕截图:虽然我不太明白为什么 Visual Studio 检测的是 VS90 而不是 VS100,但我很高兴我终于解决了这个问题,我将把这个问题留到另一天
After spending lots of time on this issue, I spoke to someone from National Instruments, and he helped me solve the issue I was having. I had previously noticed, by checking the module dependencies of
mstudiocommon.2010.msm
, that it (mstudiocommon.2010.msm
) was looking for thevs100_crt_x86.msm
file, but the installer had detected (and added) avs90_crt_x86.msm
(in the 'Detected Dependencies' of the installer project). Right-clicking the installer project and adding the VS100 .msm file manually fixed the issue that I was having.Below, is a screenshot of the module dependencies that I could see for the

mstudiocommon
andmstudioui
merge modules:Although, I didn't quite understand why Visual Studio was detecting VS90 instead of VS100, I am happy that I finally fixed this problem, and I'll leave this for another day.
尝试使用 SDK 中的 Fusion Log Viewer 来确定是哪个库导致了问题。
Try Fusion Log Viewer from SDK to identify which library causes the problem.
如果没有日志和错误消息,就很难找到问题所在。您应该在代码中放置一个
try catch
,尝试访问库组件waveformPlot
并打印错误消息和堆栈跟踪。之后你就可以看到缺少了什么。Without logs and error messages it's too difficult to find what is wrong. You should put a
try catch
in your code where you try to access the library componentswaveformPlot
and print the error message and the stacktrace. After you can see what is missing.您可以使用 Reflector 或 JustDecompile 来获取引用“NationalInstruments.Common.Native.dll”所需的内容。从它的声音来看,尽管 DLL 名称中包含“Native”一词,但它可能是其他本机 Win32 C dll 的包装。你有这些在同一个文件夹中吗?它也可能是 COM dll 的包装,但可能未注册?
You can use use either Reflector or JustDecompile to get what references 'NationalInstruments.Common.Native.dll' needs. From the sounds of it though with the word Native in the name of the DLL it maybe a wrapper around someother native Win32 C dll. Do you have those in the same folder? It may also be a wrapper around a COM dll which maybe is not registered?
我认为发生的情况是有人在目标系统上安装了仅使用最新 NI 组件子集的应用程序。为了解决这个问题,我已将 bindingRedirect 添加到 app.config 中。它起作用了。
I think what happen is that someone have installed application on target system that is using only subset of latest NI components. To fix this issue I have added bindingRedirect to app.config. It worked.
我遇到了同样的问题,当您的项目中有大量参考资料时,很难找到实际缺少的程序集。特别是如果您在没有 Visual Studio 的客户端计算机上遇到此问题。
经过一两个小时摆弄fuslogvw.exe并且无法得到明确的答案后,我只是在谷歌上搜索“检测丢失的程序集.net应用程序”并找到http://www.amberfish.net/
它就像魅力一样,有免费试用版,开发商只要求一个非常民主的价格...非常酷!
附言。我与琥珀鱼没有任何关系,今天是我第一次发现这个工具。这个人构建的工具应该在 Windows 的默认工具包中。正是我所需要的。
I had the same problem and when having tons of references in your project it's really hard to find what assembly is actually missing. Especially if you're having this problem on a clients computer without Visual Studio.
After an hour or two messing around with fuslogvw.exe and not being able to get a clear answer I just googled "detect missing assemblies .net application" and found http://www.amberfish.net/
It works like charm, there is a free trial and the developer only asks a very democratic price for it... Very Cool !!
PS. I'm in NO WAY affiliated with amberfish, today is the first time I found out about this tool. the tool this guy built should be in the default toolkit of Windows. Just what i needed.