Error adding custom control

Error adding custom control

SRSDS
Advisor Advisor
693 Views
6 Replies
Message 1 of 7

Error adding custom control

SRSDS
Advisor
Advisor

I am trying to add a custom control to a palette but when adding it from the toolbox i get an error:

"Failed to create component 'CustomCombobox, The error message follows: System.lO.FileNotFoundException: Could not load file or assembly 'Acdbmgd, Version=22.O.O.O, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."

 

I can see that the Acdbmgd.dll referenced in the project is version is 22.0.0.0 from the properties palette.

AcMgd.dll & AcCoremgd.dll also have the samve version and Copy Local=False.  

Is there anything that might be causing this?

0 Likes
Accepted solutions (1)
694 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant

Hi,

It is difficult to diagnose without seeing any code. You should, at least, show how you create the PaletteSet and add the custom control specifying if it is a Windows Form or WPF control.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 7

SRSDS
Advisor
Advisor

Hi Gile,

I'm shamefully still using VB.

I've run the palette and combobox creation code through a converter and attached the output as text files. Hoping it helps.

 

To add the combobox I rebuild, the project CustomCombobox appears in the toolbox, and I double click it to add it to the container.

AI is telling me that the combobox is a Windows Forms control. Wasn't entirely sure myself.

 

0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor
Accepted solution

Firstly, the error has nothing to do with "Copy Local" being True or False.

 

So, you have a separate DLL project that contains your CustomComboBox as Win Form UserControl, right? It looks like, this project has references to AutoCAD .NET assemblies, or at least the reference of AcdbMgd.dll.

 

So, which copy of the AcdbMgd.dll is referenced in this project? The copy in the AutoCAD install folder (i.e. the one comes with AutoCAD installation)? or the one downloaded from ObjectARX SDK download/Autodesk's Nuget package? For development, especially when you need to refer to AutoCAD .NET API in UI development, you cannot use the AutoCAD .NET references coming from AutoCAD installation, because when Visual Studio loads the custom UI in its designer, it has to load the referenced AutoCAD .NET DLL. Since the AutoCAD .NET DLL can only be loaded with AutoCAD runtime (meaning inside AutoCAD process), hence the error you saw. On the other hand, the AutoCAD .NET DLLs from the ObjectARX SDK/Nuget package is a strip-down version with the dependencies to AutoCAD runtime being removed as much as possible, so VS designer can load it (in order to get all the interfaces - properties/methods - covered by the .NET API). If you look at the file size of Acdbmgd.dll: ~2Mb from SDK/Nuget, ~6MB from AutoCAD installation. The one from SDK/Nuget is only for development, and cannot be used for running your code. That is why you MUST make sure "COPY Local" to be False.

 

Also, even you use the DLLs from SDK/Nuget, it is no guarantee, I guess, the same error will never happen.

 

Now that you go all the way to have a separate project for your custom UI components, which is a good base step of making the better code/component reusability, you might want to go one step further to separate UI with business data (AutoCAD data in this case), so that the UI component (the CustomComboBox, in your case) does not refer to any AutoCAD API data. You can search for suitable UI design patterns for this, but the most common pattern for Windows desktop app is to use WPF with MVVM pattern, with which you can easily avoid the error you ran into.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 7

SRSDS
Advisor
Advisor

Thank you!!

As you had predicted I was using the 6Mb version of AcdbMgd.dll. 

Thank you so much for your detailed explaination and tips.

0 Likes
Message 6 of 7

ActivistInvestor
Mentor
Mentor

@norman.yuan wrote:

Firstly, the error has nothing to do with "Copy Local" being True or False.

 

So, you have a separate DLL project that contains your CustomComboBox as Win Form UserControl, right? It looks like, this project has references to AutoCAD .NET assemblies, or at least the reference of AcdbMgd.dll.

 

So, which copy of the AcdbMgd.dll is referenced in this project? The copy in the AutoCAD install folder (i.e. the one comes with AutoCAD installation)? or the one downloaded from ObjectARX SDK download/Autodesk's Nuget package? For development, especially when you need to refer to AutoCAD .NET API in UI development, you cannot use the AutoCAD .NET references coming from AutoCAD installation, because when Visual Studio loads the custom UI in its designer, it has to load the referenced AutoCAD .NET DLL. Since the AutoCAD .NET DLL can only be loaded with AutoCAD runtime (meaning inside AutoCAD process), hence the error you saw. On the other hand, the AutoCAD .NET DLLs from the ObjectARX SDK/Nuget package is a strip-down version with the dependencies to AutoCAD runtime being removed as much as possible, so VS designer can load it (in order to get all the interfaces - properties/methods - covered by the .NET API). If you look at the file size of Acdbmgd.dll: ~2Mb from SDK/Nuget, ~6MB from AutoCAD installation. The one from SDK/Nuget is only for development, and cannot be used for running your code. That is why you MUST make sure "COPY Local" to be False.

I've built plenty of WinForms controls that have a dependence on AutoCAD managed assemblies, which don't require the modified reference dll's from the SDK. I also reworked the BlockView sample application (available here) that was having problems due to the same issue.

 

Another problem is that modified versions of only the basic assemblies are included in the SDK, but not other assemblies that may be needed, for which there are no modified versions. So for them, there's no choice other than to use the assemblies from the AutoCAD installation..

 

There are ways to avoid designer failures with controls and code that runs in the designer which I discuss in the thread linked to above, and also in the comments in the BlockView.NET sample.

0 Likes
Message 7 of 7

SRSDS
Advisor
Advisor

@norman.yuan wrote:

So, you have a separate DLL project that contains your CustomComboBox as Win Form UserControl, right? 


I had the class for the custom control in the main project.

I've now made it a separate DLL project and used it from there.

Another solution to the problem. Thanks again.  

0 Likes