我想检查是否安装了正确版本的 Oracle 驱动程序,并且可以在应用程序运行之前找到它,这样我就可以显示错误消息并优雅地失败。这是一个 C# Windows 窗体应用程序。
当我在没有正确版本的 Oracle 的机器上运行应用程序时,我收到以下消息并且应用程序处于挂起状态:
Could not load file or assembly 'Oracle.DataAccess, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.
如何可靠地检查此程序集是否可用?
最佳答案
除了您自己的答案之外,您还可以使用 AssemblyResolve
事件以一般方式(针对所有程序集加载问题)完成此操作。这是一个例子:
AppDomain.CurrentDomain.AssemblyResolve += (sender, prms) => {
Console.WriteLine("Could not load assembly \"{0}\".", prms.Name);
Console.ReadLine();
Environment.Exit(1);
return null;
};
Assembly.Load("this asembly does not exist");
关于c# - 检查 Oracle.DataAccess 是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8535836/