Author Topic: 2 Projects, 1 Solution, CommandMethods in both?  (Read 8453 times)

0 Members and 1 Guest are viewing this topic.

TheMaster

  • Guest
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #15 on: March 21, 2013, 11:16:22 PM »
I have a VS2010 Solution with multiple Projects, 2 of which contain multiple [CommandMethod()] definitions. The commands in the main project work fine. Those defined in the secondary project, which is referenced into the main project, are not recognized. Is there something I need to do (well, obviously there is...but what?) in order for these additional commands to be 'seen' by Autocad?

Assemblies with CommandMethods or LispFunctions must be registered for demand-loading in the registry (or via Autodesks' auto-loader).

Referencing an assembly with CommandMethods or LispFunctions from another assembly that is registered for demand-loading, will not cause those commands or LISP functions in the referenced assembly to be defined or demand-loaded, because the referenced assembly will not be loaded until a method from the referencing assembly that references a type in the referenced assembly executes for the first time.

The bottom line is that any assembly that contains CommandMethods must be registered for demand loading if you want those commands to be recognized on first use.

BlackBox

  • King Gator
  • Posts: 3770
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #16 on: March 22, 2013, 12:25:59 AM »
The ease with which you clarify development issues, never fails to impress; thanks for continuing to share your expertise for the betterment of others, Tony.
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #17 on: September 04, 2013, 10:20:18 AM »
Was testing this for another reason and remember this thread and I know this is not what you after and not a answer to your solution,
BUT taking the question literally the CommandMethods are technically in 2 different assemblies.
 ;D
Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.DatabaseServices;
  8. using Autodesk.AutoCAD.Runtime;
  9. namespace ReferencedAssembly
  10. {
  11.     public abstract class ReferencedAssemblyCommandClass
  12.     {
  13.         [CommandMethod("Fart")]
  14.         public void Fart()
  15.         {
  16.             Application.ShowAlertDialog("Fart");
  17.         }
  18.     }
  19. }
  20.  
  21.  

Code - C#: [Select]
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autodesk.AutoCAD.ApplicationServices;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.DatabaseServices;
  8. using ReferencedAssembly;
  9. using Autodesk.AutoCAD.Runtime;
  10. [assembly: CommandClass(typeof(DemandorNetLoadedAssembly.DemandorNetLoadedAssemblyCommandClass))]
  11. namespace DemandorNetLoadedAssembly
  12. {
  13.     public class DemandorNetLoadedAssemblyCommandClass : ReferencedAssemblyCommandClass
  14.     {
  15.         [CommandMethod("Poo")]
  16.         public void Poo()
  17.         {
  18.             Application.ShowAlertDialog("Poo");
  19.         }
  20.     }
  21. }
  22.  
  23.  

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #18 on: September 04, 2013, 02:53:08 PM »
 :lmao:

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #19 on: September 05, 2013, 06:58:18 PM »
Just as an aside, I have been doing a lot of work with reflection of late and as Tony mentioned, AutoCAD doesn't know about the other dll until it's loaded.
What's happening is it won't be loaded because of JIT compilation, with my reflection work all I did was create an instance of a class from the referenced assembly which demand loaded the dll, from there I was set to 'reflect' all I wanted.
I also noticed this with the same command situation with commands in another dll, I have a main dialog that loads a form from another dll via a menu, this dialog can also be called by it's own command method if needed. If I called the command only before using the menu the form wouldn't show, once I used the menu the command was loaded and available for use from then on.

So, one solution is to load the dll manually from the main dll or as a quick hack have an empty 'load' class in the referenced dll and create an instance of it at start up to load it. It will be created and disposed of quickly but the dll's will be loaded and all commands should be registered.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Jeff H

  • Needs a day job
  • Posts: 6150
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #20 on: September 16, 2013, 11:55:10 AM »
Thanks MickD,
 
Did this change when they added the AutoLoader Functionality?
 
Looking with reflector it is done through events AssemblyLoad and AssemblyResolve events.
 
I thought in the past it was not done through event handling and just whatever assembly where in registry or loaded via Netload.
 
 
Anyways I kinda like that and just done a little testing, but created a Addin-Loader that gets information to check certain folders if the files are newer than the ones in current and if so copy them over and then do a Assembly.LoadFrom.
 
Makes easier to keep people in office up to date without having to do a reinstall will have latest version on startup, and for testing just rebuild close AutoCAD and start it back up.
 
 
 
 
 
 

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #21 on: September 16, 2013, 06:51:50 PM »
Thanks MickD,
 
Did this change when they added the AutoLoader Functionality?

 
Looking with reflector it is done through events AssemblyLoad and AssemblyResolve events.
 
I thought in the past it was not done through event handling and just whatever assembly where in registry or loaded via Netload.

Not sure Jeff, I think that while an auto loader may load 'referenced' assemblies, the function being called is what triggers the auto load.
With commands, AutoCAD knows nothing about your commands until you load your assembly, that is it doesn't even know it has to resolve a reference as the callback (calling function) for the command doesn't even exist in the running process yet (it's not loaded or compiled into it).

I did see something on the board here from Dan that mentioned implementing a method that will be found to autoload .net dll's(?).
If this is the case it may be that when a command is called and the command is not registered it calls a default method which searches unloaded assemblies in the support path and if you have declared the function it will load the assembly, just thinking out load here though.

Either way you need to have a bit of code in the main process to call to make the process look for the method and resolve the reference, for plug ins in AutoCAD this is done using Netload and CommandMethod attributes to load the callbacks into the main process.

Basically what TonyT said a few posts ago :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Jeff H

  • Needs a day job
  • Posts: 6150
Re: 2 Projects, 1 Solution, CommandMethods in both?
« Reply #22 on: September 16, 2013, 07:46:59 PM »
Thanks MickD,
 
Did this change when they added the AutoLoader Functionality?

 
Looking with reflector it is done through events AssemblyLoad and AssemblyResolve events.
 
I thought in the past it was not done through event handling and just whatever assembly where in registry or loaded via Netload.

Not sure Jeff, I think that while an auto loader may load 'referenced' assemblies, the function being called is what triggers the auto load.
With commands, AutoCAD knows nothing about your commands until you load your assembly, that is it doesn't even know it has to resolve a reference as the callback (calling function) for the command doesn't even exist in the running process yet (it's not loaded or compiled into it).

I did see something on the board here from Dan that mentioned implementing a method that will be found to autoload .net dll's(?).
If this is the case it may be that when a command is called and the command is not registered it calls a default method which searches unloaded assemblies in the support path and if you have declared the function it will load the assembly, just thinking out load here though.

Either way you need to have a bit of code in the main process to call to make the process look for the method and resolve the reference, for plug ins in AutoCAD this is done using Netload and CommandMethod attributes to load the callbacks into the main process.

Basically what TonyT said a few posts ago :)

I understand that I just thought in the past the only assemblies AutoCAD parsed were ones passed via NETLOAD or were stored in the registry.
 
So no matter what implementation used that required a referenced assembly to be loaded AutoCAD did not search those assemblies. I do not have earlier version installed to see a difference.