You can try this way (also from Tony Tanzillo) which does not use Linq.
public static class EditoExtension
{
static MethodInfo runCommand =
typeof(Editor).GetMethod("RunCommand", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
public static PromptStatus Command(this Editor ed, params object[] args)
{
if (Application.DocumentManager.IsApplicationContext)
throw new InvalidOperationException("Invalid execution context for Command()");
if (ed.Document != Application.DocumentManager.MdiActiveDocument)
throw new InvalidOperationException("Document is not active");
return (PromptStatus)runCommand.Invoke(ed, new object[] { args });
}
}
If it still doesn't work, you have to P/Invoke the unmanaged acedCmd method.
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", EntryPoint = "acedCmd",
CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedCmd(IntPtr resbuf);
/// <summary>
/// Call an AutoCAD command (works synchronously).
/// </summary>
/// <param name="args">A ResultBuffer containing the command name followed by command inputs.</param>
public static void Command(ResultBuffer args)
{
acedCmd(args.UnmanagedObject);
}