tags:

views:

170

answers:

3

Hi,

I have application which needs to use a dll (also written by me) which has be independently verified by a government agency. We plan to modify the dll very rarely due to the re-verification which would be required. I want to prevent inadvertent modifications to this dll being picked up by my application. Is there a way to create a hash code for the dll and set up my application to only use this specific version.

This way if someone modified some of the code for the dll, when we build and run the application the app would fail to load the dll (because it had changed).

Any ideas/suggestions?

Cheers,

James

+2  A: 

I know that if you click on a dll Reference in your project you can select 'Specific Version' in its properties and set it to True, will this not do what you are after?

Phill

Phill Duffy
This will work providing the version number is incremented when the new version of the assembly is built. If you control your assmebly version numbers so that they don't have a unique build number, this won't offer you sufficient protection as more than one build can have the same version number (poor practice, but it happens).
Colin Desmond
+3  A: 

Using Strong Names does part of this and prevent anyone else tampering with your assembly, but doesn't stop you doing it by accident and then resigning.

We use an independent process to start our main application. Before launching the main app, the start up app MD5's all the assmeblies and compares them against a list of those it expects to see, if something has changed, the MD5 fails and the main app is not loaded.

If you really wanted compile time checking, you could probably write a pre-build step that did the same MD5 comparison and failed the build if it had changed.

Colin Desmond
+1  A: 

As Colin mentioned Strong Naming your assemblies will be the key as this includes both versioning & signing the assembly. The following couple of blog posts may help you with strong naming & versioning:

http://www.csharp411.com/net-assembly-faq-part-3-strong-names-and-signing/ (might be also worth reading the next part of this about the Global Assembly Cache)

http://philippetruche.wordpress.com/2008/08/12/net-assembly-versioning-lifecycle/

mundeep