Search code examples
c#gac

Call method with assembly loaded from GAC


I am trying to call the Save method from a System.Drawing.Image object, after loading the assembly from the GAC:

_drawingAssembly = Assembly.Load
                    ("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

_drawingAssembly.GetType("Image").GetMethod("Save").Invoke(myImageObject, new object[] { path });

But it's not working. I can't even get the type for some reason; this returns null:

var t = _drawingAssembly.GetType("Image"); // null

Solution

  • You need to specify the full type name System.Drawing.Image as indicated by the documentation:

    https://msdn.microsoft.com/en-us/library/y0cd10tb(v=vs.110).aspx