How to validate that a DLL was loaded properly?
At work we use a particular in-house DLL almost everywhere. It's constantly being updated and often times we'll use it in both 32 and 64 bit applications. It's a C++ DL开发者_Go百科L in Mixed Mode (so I'm told, I don't know much about C++ DLL configuration and build parameters so I'm passing along what I hear) and our applications are in C# ranging from 2.0 to 4.0. Because of the fact that this DLL is everywhere, sometimes older versions get grabbed when it's needed (grabbed from a project that requires an older version).
I use this DLL in a vital place in my latest project. It would be much better to fail early on because of the wrong version of the DLL being used rather than fail at the crucial moment that the DLL is actually required. What techniques are available to verify a DLL will work early on in code?
I suppose I could try to use an object out of the DLL, but I feel this is a semi-sloppy solution, just creating an object to see if you can, not to mention that this technique wouldn't work if the DLL didn't contain objects that could be instantiated and all other methods may cause unwanted impact on the OS, a database, or internal state. A second idea I had was (since this DLL is in-house) to have it include a method with this in mind. A do-nothing method just for verifying the DLL will work. However, I know this won't work for non-in-house DLLs and this feels like a very unprofessional solution.
Perhaps call System.Reflection.Assembly.GetAssembly
to ensure you're using the correct version (or the version you think you are)?
精彩评论