TheSwamp

Code Red => .NET => Topic started by: mastrolube on March 22, 2021, 06:14:58 AM

Title: CommandMethod not recognized
Post by: mastrolube 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 .... :(
Title: Re: CommandMethod not recognized
Post by: huiz on March 22, 2021, 06:56:08 AM
Your class should be public, I think.
Title: Re: CommandMethod not recognized
Post by: Hanauer on March 23, 2021, 08:08:04 AM
Did you select the correct .NET version?
For AutoCAD 2020: .NET Framework 4.7.
Title: Re: CommandMethod not recognized
Post by: CADbloke 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.
Title: Re: CommandMethod not recognized
Post by: Bryco 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
    {
Title: Re: CommandMethod not recognized
Post by: CADbloke on May 07, 2021, 04:03:14 PM
class ControlsDemoUtil needs to be public class ControlsDemoUtil
Title: Re: CommandMethod not recognized
Post by: MickD 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.  
Title: Re: CommandMethod not recognized
Post by: jtoverka on May 10, 2021, 07:28:07 AM
Am I the only one that uses public static class to declare methods and lisp functions?
Title: Re: CommandMethod not recognized
Post by: Jeff H 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.