Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C# | Created a dll to reference in my addin, but VS can't find it.

2 REPLIES 2
Reply
Message 1 of 3
jardmettle
254 Views, 2 Replies

C# | Created a dll to reference in my addin, but VS can't find it.

Hello,

I wrote an addin for Autocad and Inventor. I often reference the same directories and other common code between the two. So I created a dll with file paths and directoryinfo objects to start with. Can you help understand how to create a dll and use it in any solution?

The error I get is that it can't find the dll:

jmettlerCVRU2_1-1719264755592.png

 

Description of the DLL:

I created a class library (.NET Framework); green box below. The red box is another format of class library I tried "and failed".

jmettlerCVRU2_0-1719262359968.png

Class library code.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using SysInter = System.Runtime.InteropServices;
using Win = System.Windows;
using DB = System.Diagnostics.Debug; // Shortens code to print to the output tab below
using DBR = System.Diagnostics.Debugger; // Shortens code to pause execution of code
using Env = System.Environment;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Windows.Forms;
using Thrd = System.Threading.Thread;
using System.IO;
using System.Drawing;
using System.Net.NetworkInformation;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
using System.Diagnostics;
using static System.Net.WebRequestMethods;

namespace CadLibrary
{
    public class CompanyStuff
    {
        private static string LocalFolderPath = "C:\\Acad Files";
        private static string ServerFolderPath = "\\\\<Server>\\AutoCAD\\Acad Files";
        /// <summary>
        /// The local folder path C:\Acad Files.
        /// </summary>
        public static string LocalPath {get { return LocalFolderPath; }}
        /// <summary>
        /// The folder path of the autocad directory on the server.
        /// </summary>
        public static string ServerPath_AutoCAD = ServerFolderPath;
        /// <summary>
        /// The directory object of the local folder path.
        /// </summary>
        public static DirectoryInfo LocalDirectory = new DirectoryInfo(LocalFolderPath);
        /// <summary>
        /// The directory object of the server folder path for AutoCAD files.
        /// </summary>
        public static DirectoryInfo ServerDirectory_AutoCAD = new DirectoryInfo(ServerFolderPath);

    }

}

 

 

In my Addin I added the DLL as a reference. At the top I added: "using CadLibrary.CompanyStuff". I'm leaving a lot of code out since it doesn't seem important to what I'm trying to accomplish. Anyway, the code that gets the error is surrounded by --\/-- & --/\--. 

using Autodesk.AutoCAD.Internal.Windows;
using MyStuff;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Interop;
using SysInter = System.Runtime.InteropServices;
using DB = System.Diagnostics.Debug; // Shortens code to print to the output tab below
using DBR = System.Diagnostics.Debugger; // Shortens code to pause execution of code
using Env = System.Environment;
//using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using CadApp = Autodesk.AutoCAD.ApplicationServices;
//using Autodesk.AutoCAD.ApplicationServices.Application;
using CadEdIn = Autodesk.AutoCAD.EditorInput;
using CadDBS = Autodesk.AutoCAD.DatabaseServices;
using CadGeo = Autodesk.AutoCAD.Geometry;
using CadPrint = Autodesk.AutoCAD.PlottingServices;
using CadPubl = Autodesk.AutoCAD.Publishing;
using CadCui = Autodesk.AutoCAD.Customization; //<-- used for developing CUIX files
using CadWin = Autodesk.Windows; //<--(aduimgd.dll & adwindows.dll) used for classes and enum for ribbon
using Autodesk.AutoCAD.Customization;
using CadRun = Autodesk.AutoCAD.Runtime;
using MyStuff;
using Msg = MyStuff.Message;
using Emp = CompanyAutocadAddinC;
using Win = System.Windows;
using VbFile = Microsoft.VisualBasic.FileIO;
using MyG = MyStuff._G;
using Rsrc=CompanyAutocadAddinC.Properties.Resources;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using System.Drawing;
using System.Windows.Media;
using CadColr = Autodesk.AutoCAD.Colors;
using System.Security.Cryptography;
using System.Diagnostics;
using CadLib = CadLibrary.CompanyStuff; // Created this library so all Company info is in one place.
using System.IO;
using System.Runtime.InteropServices.ComTypes;
using System.Reflection;

namespace CompanyAutocadAddinC
{
    public class ServiceCommands
    {

        #region Emp_Update
        [CadRun.CommandMethod("Emp_Update")]
        public void Emp_Update()
        {
            string CodeLocation = "ServiceCommands | Emp_Update";
            bool PrintToOutput = true;
            if (PrintToOutput) { Msg.Print(CodeLocation, PrintType.Output, $"\n{CodeLocation} | Started...\n"); }

            // Layouts are sorted by taborder during the globals.GetLayouts sub during initiate
            // Target is referenced to the dwg I'm currently working and want to add a new layout to -Any globals "g_" assume this too
            // Temp/Template is referenced to,  the layout of, or anything else pertaining to the template
            MyG.Initiate();

\\ --\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--\/--
            string LocPath = CadLibrary.CompanyStuff.LocalPath;
\\ --/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--/\--

            FileInfo LocalFile;
            FileInfo ServerFile;
            // Narrow down which local file to replace
            try
            {

                //LocalFile = new FileInfo(CadLib.LocalPath + "\\UpdateFromServer.exe");
                //ServerFile = new FileInfo(CadLib.ServerPath_AutoCAD + "\\UpdateFromServer.exe");
                //if (PrintToOutput) { Message.Print(CodeLocation, PrintType.OutputCad, $"...\tUpdateFromServer.exe | Found on Server: {ServerFile.Exists} | Found Locally: {LocalFile.Exists}"); }
            }
            catch (Exception ex) { Message.Print(CodeLocation, PrintType.OutputCad, $"{CodeLocation} | Ended... | Couldn't find the update program.\n"); ; return; }

            //// Pause code
            //DBR.Break();

            // Compare modified dates
            //DateTime ServerDate = ServerFile.LastWriteTime;
            //DateTime LocalDate = LocalFile.LastWriteTime;
            //if (PrintToOutput) { Message.Print(CodeLocation, PrintType.OutputCad, $"...\tFile: {ServerFile.Name} | Server datetime: {ServerDate.ToString()} | Local datetime: {LocalDate.ToString()}"); }

            // Update the UpdateFromServer program
            try
            { 
                //if (ServerDate > LocalDate) { ServerFile.CopyTo(CadLib.LocalPath, true); }
            }
            catch (Exception ex ) { Message.Print(CodeLocation, PrintType.OutputCad, $"{CodeLocation} | Ended... | Couldn't upgrade the update program.\n"); return; }
            

            try
                {
                //Process.Start(CadLib.LocalPath + "\\UpdateFromServer.exe"); 
            }
            catch (System.Exception ex)
            {
                Message.Print(CodeLocation, PrintType.OutputCad, $"{CodeLocation} | Ended... | Couldn't run the update from server program.\n");
                return;
            }

            //try { HandleCuix(); }
            //catch (System.Exception ex)
            //{
            //    DB.WriteLine($"{CodeLocation} | Ended... | Couldn't complete the cuix command.\n");
            //    return;
            //}

            if (PrintToOutput) { Msg.Print(CodeLocation, PrintType.Output, $"\n{CodeLocation} | Ended...\n"); }

        }
        #endregion

    }
}

 

 

 

 

 

2 REPLIES 2
Message 2 of 3

I tried with minimal code from the sample you provided. Looks like the first project builds fine and in the second project, i.e., the plugin, right-click on the project -> Add -> Reference -> Browse -> select your dll (from first project's bin folder). After this, the compiler is correctly accessing the below lines.

string LocPath = CadLibrary.CompanyStuff.LocalPath;
//or
string LocPath = CadLib.LocalPath;

 Did you add reference correctly and from the right bin folder? Do let me know if it gets resolved with this.

For more support, share small reproducible projects and I'll look into them. 

Message 3 of 3
kdub_nz
in reply to: jardmettle

@jardmettle 


@jardmettle wrote:

>>>>

Description of the DLL:

I created a class library (.NET Framework); green box below. The red box is another format of class library I tried "and failed".

jmettlerCVRU2_0-1719262359968.png

<<<<


Which version of AutoCAD are you building for ??

You really should study and know the difference between the Class library versions.

 

Regards,

 

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.
Sometimes the question is more important than the answer.

class keyThumper<T> : Lazy<T>;      another  Swamper

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report