views:

87

answers:

3

The title says it all.

Since, it's possible for anyone to name an assembly starting with 'System', checking for 'System' is not a satisfactory solution.

Alternatively, if that's not possible, how about checking the modules in an assembly?

+2  A: 

All .NET assemblies might have the same public key token: b77a5c561934e089

winSharp93
I just checked with reflector, and while many do have that key, others have the key .....e35.There only appears to be 2 different keys, but then I only have a limited number of assemlies loaded into reflector.It looks promising though. Cheers for what must be the faster answer on SO!
Jules
Here's a post that goes into more detail including verifying the signature as well as verifying the token:http://blogs.msdn.com/shawnfa/archive/2004/06/07/150378.aspx
Chris Haas
The problem with the solution is that, since that post in 2004, there are now 3 more keys to check for. The easiest way to check is to have a look at the GAC folder at: <windowsfolder>\assembly
Jules
If there are no other answers, though, i'll go with the key check as the worse thing that can happen, if i pick up a framework assembly, is a performance hit.
Jules
Performance? You could try the opposite way: "Whitelist" all wanted assemblies with a custom attribute and check this before e.g. looping all types in the assembly.
winSharp93
I can't do this because I have no control over the assemblies the derived type may in in.
Jules
If you can get the Product Name property of the dll, and check for the name "Microsoft .Net Framework". Of course someone could use this in another assembly.
Mikael Svenson
+2  A: 

It is a moving target. For example, the PrintForm component wasn't originally part of the framework install set, but it is in .NET 3.5 SP1. The very best thing to do is to not ask the question, you'll get in trouble some day when you do.

Hans Passant
+1  A: 

If you're not too concerned with security then you could simply check the path

Console.WriteLine(typeof(File).Assembly.Location.EndsWith(@"Microsoft.NET\Framework64\v2.0.50727\mscorlib.dll"));

Otherwise, as already suggested, the public key token on the fullname would be safest:

Console.WriteLine(typeof(File).Assembly.FullName.Contains("PublicKeyToken=b77a5c561934e089"));
Chris S