public static int ThrowOnFailure(int hr, params int[] expectedHRFailure) { if (VSErr.Failed(hr)) { if (expectedHRFailure != null) { foreach (int i in expectedHRFailure) { if (i == hr) { return(i); } } } Marshal.ThrowExceptionForHR(hr); } return(S_OK); }