Author Topic: CommandMethod not recognized  (Read 3186 times)

0 Members and 1 Guest are viewing this topic.

mastrolube

  • Mosquito
  • Posts: 3
CommandMethod not recognized
« on: March 22, 2021, 06:14:58 AM »
Hello everyone!
I've a problem running .dll I made.. I'm following a course on udemy, but for me it doens't load anything.. Anyone can tell me what's the problem?
I've a solution with that class:
Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
[code]
namespace ControlsDemo
{
    class ControlsDemoUtil
    {
        [CommandMethod("Test")]
        public void Demo()
        {
            MainForm mf = new MainForm();
            mf.Show();
        }
    }
}

when I load the DLL with netload, keyword "Test" is not recognized (It's not even there!)
I compiled using as references AcCoreMgd, AcDbMgd and AcMgd with version 23.1 (I'm running Autocad 2020)
I don't understand what I'm missing, I already did a DLL following the AutoCAD tutorial and this worked just fine (it was a while ago..).
I don't get where this simple few rows code fails.. If I don't find out Iill not able to go ahead with the tutorial .... :(

huiz

  • Swamp Rat
  • Posts: 913
  • Certified Prof C3D
Re: CommandMethod not recognized
« Reply #1 on: March 22, 2021, 06:56:08 AM »
Your class should be public, I think.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Hanauer

  • Mosquito
  • Posts: 10
Re: CommandMethod not recognized
« Reply #2 on: March 23, 2021, 08:08:04 AM »
Did you select the correct .NET version?
For AutoCAD 2020: .NET Framework 4.7.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CommandMethod not recognized
« Reply #3 on: March 26, 2021, 06:09:04 AM »
@huiz is right. A class is internal by default unless you declare it public. Command classes and methods must be public. The public method in the internal class can only be internal, its access is restricted by the access level of the class.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: CommandMethod not recognized
« Reply #4 on: May 07, 2021, 02:34:13 PM »
[assembly: CommandClass(typeof(ControlsDemo.class ControlsDemoUtil))]


I run commands from an internal class but I do have the command class which the code above appears to be missing
namespace cnc
{
    internal class Cnc
    {

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: CommandMethod not recognized
« Reply #5 on: May 07, 2021, 04:03:14 PM »
class ControlsDemoUtil needs to be public class ControlsDemoUtil

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: CommandMethod not recognized
« Reply #6 on: May 08, 2021, 10:05:51 PM »
I set up my app's with the bare minimum of an Entry class and Commands class and you need to(?) let the runtime know by using the 'assembly' annotations. Of course, these classes need to be public.
hth

Code - C#: [Select]
  1. // set up the entry point:
  2. [assembly: ExtensionApplication(typeof(MyAppNameSpace.MyAppEntry))]
  3.  
  4. // let cad know what our commands class name is:
  5. [assembly: CommandClass(typeof(MyAppNameSpace.Commands))]
  6.  
  7. namespace MyAppNameSpace
  8. {
  9.     ///
  10.     /// This class is the entry point for BricsCAD/Autocad, it get's called at least once
  11.     /// when you use 'Netload' to load and configure your application
  12.     /// There can only be one instance of inherited IExtensionApplication
  13.     /// per class library.
  14.     /// This class can be used to store app wide (global like) variables and methods and initialisations.
  15.     ///
  16.     public class MyAppEntry : IExtensionApplication
  17.     {
  18.           // do stuff here:
  19.  
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

jtoverka

  • Newt
  • Posts: 127
Re: CommandMethod not recognized
« Reply #7 on: May 10, 2021, 07:28:07 AM »
Am I the only one that uses public static class to declare methods and lisp functions?

Jeff H

  • Needs a day job
  • Posts: 6144
Re: CommandMethod not recognized
« Reply #8 on: May 10, 2021, 09:12:42 PM »
Am I the only one that uses public static class to declare methods and lisp functions?
Depends,
If you want to have different instance for each document, where you might store data in properties of the command class that ae document dependent then you would not want to make it static.