Jun 15, 2010 at 1:08 PM
Edited Jun 16, 2010 at 10:58 AM

There is an error with that static BitmapBuffer() function when trying to view the "2D Example" tab in Designer view, because of wrong assumption that the very first method returned by GetMethods() is always the Lock() method.

The exception raised by Designer (Shift+F7) view is System.Reflection.TargetParameterCountException "Parameter count mismatch."

During run time the returned array is "Lock", "SetResolution", "SetPalette" as authors have expected.

During design time the returned array is "SetResolution", "Lock", "SetPalette" as authors have NOT expected.

The correct code piece follows.

MethodInfo[] info = wicBitmapNativeMethodsClass.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
/* This method looks good */
//_lockmethod = info[0]; // No, it does NOT look good this way during design time!!!
for (int i = 0; i < info.Length; i++)
    MethodInfo myMethodInfo = (MethodInfo)info[i];
    if (myMethodInfo.Name == "Lock") { _lockmethod = myMethodInfo; }

Jun 18, 2010 at 7:44 AM

Even better than that is a single line short code to receive the required internal static method "Lock".

_lockmethod = wicBitmapNativeMethodsClass.GetMethod("Lock", BindingFlags.Static | BindingFlags.NonPublic);