【发布时间】:2011-05-31 04:41:13
【问题描述】:
我正在编写一个 .NET 3.5 应用程序 (WinForms),它使用来自外部 DLL 的类,并且每次尝试启动应用程序时,我都会不断收到 System.TypeLoadException。
这是 VS 显示的异常:
这是我正在运行的代码:
Friend NotInheritable Class App
<STAThread()> Shared Sub Main()
'set the exception handlers'
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler
AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
'initialize the application'
App.Initialize()
'and then run the application'
Dim mainForm As New PolymorphHost
Application.Run(mainForm)
End Sub
Shared Function Initialize() As FunctionResult
If App.InitializeDataDirectory() = False Then
Return New FunctionResult(False, "the application's data directory")
End If
_settings = New PolyMorph.Common.Settings(AppDataDirectory & "\Settings.dat")
......code continues to load settings from the _settings variable
End Function
End Class
让我吃惊的是,VS2010 Debugger 在App.Initialize() 行停止,甚至没有进入Initialize 函数。
但是,如果我在 Initialize 函数中注释掉对外部 DLL 的所有引用,则应用程序会正确初始化。
阅读后,我意识到许多报告此错误的人在他们的项目中使用不同的构建(例如从 x86 应用程序引用的 x64 DLL)。因此,我更改了构建配置,因此 DLL 和应用程序都是 x86,但我仍然拥有 TypeLoadException。
我有什么遗漏的吗?
【问题讨论】:
-
当我的应用程序清单中的 dll 名称错误时出现此错误。
标签: .net vb.net exception typeloadexception