开发者

Disable application functionality when missing assembly

I'm building an application 开发者_运维百科that uses the Oracle.DataAccess.dll to connect to a database to do some work. The database access isn't necessary to perform 90% of what the application does and the application loads fine without the dll thanks to JIT loading. However, it does crash when accessing the specific part of the application that uses the dll when it's not present.

I'd like to be able to disable access to that form proactively when the dll is missing, is there any way to detect that dll at application load?

Update:

I was able to find a potential solution by doing

if (!File.Exists("Path to Oracle.DataAccess.dll"))
{
     toolStripMenuItem.Enabled = false;
}

Are there any better solutions out there?


You could try Assembly.Load and see if it works; otherwise, perhaps GetLoadedModules may do what you need. A path search isn't going to work as it'd exclude the GAC and other places assemblies can be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜