.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Oddity with ExtensionApplication attribute and IExtensionApplication

9 REPLIES 9
Reply
Message 1 of 10
tumpliner
935 Views, 9 Replies

Oddity with ExtensionApplication attribute and IExtensionApplication

Hello,
I am trying to make an application with both reactors or callbacks in C# (whatever they are called), and also with command-line invoked commands. So.. I have successfully gotten the command line methods to be invoked using the CommandMethod attribute. I also have successfully gotten the callback functions loaded and called. The odd thing is that they are not compatible with each other. As soon as I put the ExtensionApplication attribute in then the CommandMethod functionality is gone. All I get from that point is "Command not found". As soon as I take the Extension Application attribute with : IExtensionApplication declaration back out then the commands start working again.
Yes, I have acmgd and acdbmgd referenced. No, there are no local copies, and Copy Local is set to false on all references.
Yes, I have tried the Lab 6 of the Autodesk Sample Code, in which both callbacks and command methods are used. Yes, it works fine. Yes, I have compared the Assembly Files of both of them and made them the same. Still does not work. Yes, I have tried the CommandClass attribute. Without the ExtensionApplication attribute the commands can be invoked with or without the CommandClass attribute.
Anyone ever come across this problem and found a solution? I am using AutoCAD 2009 with Visual Studio 2005.

Thanks
9 REPLIES 9
Message 2 of 10

Not helpful, I know but: Is there any explanation why the CommandClassAttribute should be there? Whether it's there or not, my code keeps working the way I want it to...



Maybe helpful: I have had mysteriously not-working commands a while ago. When double checking everything you're mentioning, we didn't see any obvious problems. However, there was one command that was declared twice with the CommandMethodAttribute. As a result, some of the commands were no longer recognised. Maybe that's your problem?



If adding/removing CommandClassAttribute is the only factor that's affecting the "Command not found", then I'm afraid I can't help you.



--



http://cupocadnet.blogspot.com
Message 3 of 10
Anonymous
in reply to: tumpliner

The most common cause of command methods not
being recognized, is when the code called from an
IExtensionApplication's Initialize() method throws an
exception.

Unfortunately, Autodesk seems to think that it's ok to
completely supress the exception without offering so
much as a hint that it happened, so unless you run the
code in the debugger, you'll never know it happened.

My advice is to write your Initialize() method like this:

{code}

public void Initialize()
{
try
{
// TODO: Initialize your app here
}
catch( System.Exception ex )
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
ex.ToString() );
throw;
}
}

{code}


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6138953@discussion.autodesk.com...
Hello, I am trying to make an application with both reactors or callbacks in
C# (whatever they are called), and also with command-line invoked commands.
So.. I have successfully gotten the command line methods to be invoked using
the CommandMethod attribute. I also have successfully gotten the callback
functions loaded and called. The odd thing is that they are not compatible
with each other. As soon as I put the ExtensionApplication attribute in then
the CommandMethod functionality is gone. All I get from that point is
"Command not found". As soon as I take the Extension Application attribute
with : IExtensionApplication declaration back out then the commands start
working again. Yes, I have acmgd and acdbmgd referenced. No, there are no
local copies, and Copy Local is set to false on all references. Yes, I have
tried the Lab 6 of the Autodesk Sample Code, in which both callbacks and
command methods are used. Yes, it works fine. Yes, I have compared the
Assembly Files of both of them and made them the same. Still does not work.
Yes, I have tried the CommandClass attribute. Without the
ExtensionApplication attribute the commands can be invoked with or without
the CommandClass attribute. Anyone ever come across this problem and found a
solution? I am using AutoCAD 2009 with Visual Studio 2005. Thanks
Message 4 of 10
tumpliner
in reply to: tumpliner

There doesn't seem to be any need for the CommandClassAttribute. The code seems to work the same regardless of whether it is there or not. I only put it in to see if its absence was the cause of the problem.

Really, though, the commands with CommandMethod attribute always work fine, except when the ExtensionApplicationAttribute is also present. Then they never work at all. Another thing is that if I take out the ExtensionApplicationAttribute, but leave in the : IExtensionApplication interface (along with its implementation of Initialize() and Terminate() ) then the CommandMethod attributed commands still do not work. So actually, it looks like there is something strange going on with this interface, but I don't know what. If I take out the
: IExtensionApplication interface declaration (but leave the Initialize() and Terminate() ) then the CommandMethods will once again work. So, again, it looks like the interface declaration, and not the actual implementation of Initialize and Terminate, is what is causing the problem.

Thanks again
Message 5 of 10
tumpliner
in reply to: tumpliner

Yes, that was the problem. Thanks! It was hitting an exception while carrying out the Initialization, and I had not realized it.
Message 6 of 10
aSaRichB
in reply to: tumpliner

Hello,

 

I am experiencing this same problem.   Everything was working at one point.  I am not really sure what I did that caused it to stop working.  I think the last thing I did was change the one and only Command Name to something different.  I have done everything mentioned in this Message thread.  I just started my project, so it doesn't really have much to it.  It must be loading the DLL, because access is denied to me when I try to rebuild it.  I am just using NETLOAD to load it.  I put in code to catch an exception during the class constructor and for the extension class initialize, but no exception is thrown.  I am not really doing anything during the initialize. I just ouput a message to the Auto Desk editor.  Does anyone have an idea why this is happening?  I have tried creating a new project from scratch using the same and/or slightly different name and it still does not work.

 

Thank you,

Rich

Message 7 of 10
Anonymous
in reply to: aSaRichB

I had the same problem it was I accidently put a command method in a different file in the assembly.

When I say file a mean .vs or .cs file

I copied and pasted a command method similiar to what I needed and modified it and forgot to erase the command Atribute

So when netloaded Autocad only recongnized that one command Attribute and none of the other commands were recognized and the intiaialize and terminate never ran.

 

 

Message 8 of 10
aSaRichB
in reply to: tumpliner

I see, so you had 2 different commands with the same name?  Are you talking about this attribute?         


        [CommandMethod("<ACAD_CMD_NAME>", CommandFlags.Session)]
        public void AcadCmdNameCommand()
        {

Message 9 of 10
aSaRichB
in reply to: tumpliner

I think I figured out why the initialize was not getting hit for my Extended Application form. It is because I added a parameter to the Extension Application Form Constructor and the Class did not have a Constructor that took 0 parameters. I guess it is good to have a Constructor that takes 0 parameters anyways. I am surprised that I didn't get a warning or anything about that during the build.  Seems like a dumb mistake on my part (User Error). haha

 

Thank you,

Rich

Message 10 of 10
Anonymous
in reply to: aSaRichB

If you're implmementing IExtensionApplication on a Form, that's a no-no.

 

AutoCAD creates the instance of the class, and you don't want it to

create an instance of your form.

 

You shouldn't implement IExtensionApplication on any class that you

will create instances of manually.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost