0

I would like to load an assembly from the GAC, but I don't know its version. I do know the AssemblyName and PublicKeyToken.

string dllname="gacname"; //Name os assembly  
AssemblyName name = new AssemblyName(string.Format("{0}, PublicKeyToken=dd3cb1c9aae9ec97" ,dllname));
var x = Assembly.Load(name);

This code throws an exception:

Could not load file or assembly ...

The dllname is correct, because it works fine when I specify the version in the AssemblyName.

Is it possible to do this without knowing the version?

ígor
  • 1,144
  • 7
  • 16
  • @igor - If you are asking for a way to load the assembly without having to know the version, then please state that more clearly in the question. Your question says "..., but I don't know its version"; to me that implies you are indirectly asking for help of how to find that version. – Karl Anderson Jul 11 '13 at 16:57

2 Answers2

0

Have you tried looking at the contents of the GAC? You can do so by initiating the following command:

gacutil -l

This should tell you the version of your assembly.

Please read the MSDN documentation for How to: View the Contents of the Global Assembly Cache

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • I don't think this is what @igor is asking as this doesn't help load an assembly without knowing it's version. – Fishcake Jul 11 '13 at 15:59
  • 1
    The way the question is stated is that he does not know the version, thus I was telling him how to find the version. If @igor does not want to know the version, then he should probably state that in the question. – Karl Anderson Jul 11 '13 at 16:55
0

Though it's deprecated, have you tried Assembly.LoadWithPartialName(dllname); ?

hoang
  • 1,887
  • 1
  • 24
  • 34