15internal static class ComInvoker
73 public static void SetProperty(
object target,
string name,
object? value)
77 target.GetType().InvokeMember(
79 BindingFlags.SetProperty,
83 CultureInfo.InvariantCulture);
85 catch (TargetInvocationException ex) when (ex.InnerException is not
null)
87 throw CreateDetailedException($
"MX Component property '{name}'", ex);
147 public static object? Invoke(
object target,
string name, params
object?[] args)
151 return target.GetType().InvokeMember(
153 BindingFlags.InvokeMethod,
157 CultureInfo.InvariantCulture);
159 catch (TargetInvocationException ex) when (ex.InnerException is not
null)
161 throw CreateDetailedException($
"MX Component method '{name}'", ex);
237 public static object? InvokeWithByRef(
object target,
string name,
object?[] args, params
int[] byRefIndexes)
239 var modifiers =
new ParameterModifier(args.Length);
240 foreach (var index
in byRefIndexes)
242 modifiers[index] =
true;
247 return target.GetType().InvokeMember(
249 BindingFlags.InvokeMethod,
254 CultureInfo.InvariantCulture,
255 namedParameters:
null);
257 catch (TargetInvocationException ex) when (ex.InnerException is not
null)
259 throw CreateDetailedException($
"MX Component method '{name}'", ex);
303 public static int ToReturnCode(
object? value)
305 return value is
null ? 0 : Convert.ToInt32(value, CultureInfo.InvariantCulture);
340 private static InvalidOperationException CreateDetailedException(
string operation, TargetInvocationException exception)
342 var message =
new StringBuilder(operation);
343 message.Append(
" failed.");
345 for (Exception? current = exception.InnerException; current is not
null; current = current.InnerException)
348 .Append(current.GetType().Name)
350 .Append(current.Message);
353 if (message.ToString().Contains(
"System.ServiceModel.AddressAlreadyInUseException", StringComparison.Ordinal))
355 message.Append(
" Mitsubishi MX Component 64-bit DotUtlType64 wrapper depends on legacy .NET Framework WCF types that are not available in this .NET runtime. Run the sample as x86 with ProgID 'ActUtlType.ActUtlType', or host the MX 64-bit wrapper from a .NET Framework process.");
358 return new InvalidOperationException(message.ToString(), exception.InnerException);