<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Unable to load an assembly properly. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950433#M8890</link>
    <description>&lt;P&gt;Hello all.&lt;/P&gt;&lt;P&gt;I've taken the plunge to learn C# programming, and am having some trouble to get my first assembly to load properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i run NETLOAD, it either seems to work just fine. That is, there isn't anything returned to the command line (but i'm not sure if it should say the .dll was loaded properly), or once it said "unable to load ...address..DrawObjects.dll"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i don't get the latter error message, and try to type in the command method, it just says "unknown command".&lt;/P&gt;&lt;P&gt;Is there anything in the code below that is obviously wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using AutoCAD 2023, and have the accoremgd, Acdbmgd &amp;amp; Acmgd assemblies set to not copy local in VisualStudio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

namespace DrawObjects
{
    public class DrawObject
    {
        [CommandMethod("DRAWCIRCLE")]
        public void DrawCircle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    doc.Editor.WriteMessage("Drawing a circle.");
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    
                    // specify the circle's parameters
                    Point3d centerPt = new Point3d(100, 100, 0);
                    double circleRad = 100.0;
                    using (Circle circle = new Circle())
                        
                    {
                        circle.Radius = circleRad;
                        circle.Center = centerPt;
                        circle.Layer = "ELEV_LIGHT";
                        

                        btr.AppendEntity(circle);
                        trans.AddNewlyCreatedDBObject(circle, true);
                    }
                    trans.Commit();

                }
                catch (System.Exception ex)
                {

                    doc.Editor.WriteMessage("Error encountered: " + ex.Message);
                    trans.Abort();
                }

            }
        }

        [CommandMethod("DRAWMTEXT")]
        public void DrawMText()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor edt = doc.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    edt.WriteMessage("Drawing MText Exercise!");
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;

                    // specify the Mtext parameters
                    string txt = "Hello AutoCAD, from cSharp.";
                    Point3d insPt = new Point3d(200, 200, 0);
                    using (MText mtx = new MText())
                    {
                        mtx.Contents = txt;
                        mtx.Location = insPt;

                        btr.AppendEntity(mtx);
                        trans.AddNewlyCreatedDBObject(mtx, true);
                    }
                    trans.Commit();
                }
                catch (System.Exception ex)
                {

                    edt.WriteMessage("Error encountered: " + ex.Message);
                    trans.Abort();
                }
            }
        }

        [CommandMethod("DRAWLINE")]
        public void DrawLine()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor edt = doc.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    // send a message to the user
                    edt.WriteMessage("\nDrawing a Line object");
                    Point3d pt1 = new Point3d(0, 0, 0);
                    Point3d pt2 = new Point3d(100, 100, 0);
                    Line ln = new Line(pt1, pt2);
                    ln.ColorIndex = 8;
                    btr.AppendEntity(ln);
                    trans.AddNewlyCreatedDBObject(ln, true);
                    trans.Commit();

                }
                catch (System.Exception ex)
                {

                    edt.WriteMessage("Error was encountered: " + ex.Message);
                    trans.Abort();
                }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 01:30:20 GMT</pubDate>
    <dc:creator>Jeremiah.Dillashaw</dc:creator>
    <dc:date>2023-05-09T01:30:20Z</dc:date>
    <item>
      <title>Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950433#M8890</link>
      <description>&lt;P&gt;Hello all.&lt;/P&gt;&lt;P&gt;I've taken the plunge to learn C# programming, and am having some trouble to get my first assembly to load properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i run NETLOAD, it either seems to work just fine. That is, there isn't anything returned to the command line (but i'm not sure if it should say the .dll was loaded properly), or once it said "unable to load ...address..DrawObjects.dll"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If i don't get the latter error message, and try to type in the command method, it just says "unknown command".&lt;/P&gt;&lt;P&gt;Is there anything in the code below that is obviously wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using AutoCAD 2023, and have the accoremgd, Acdbmgd &amp;amp; Acmgd assemblies set to not copy local in VisualStudio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

namespace DrawObjects
{
    public class DrawObject
    {
        [CommandMethod("DRAWCIRCLE")]
        public void DrawCircle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    doc.Editor.WriteMessage("Drawing a circle.");
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    
                    // specify the circle's parameters
                    Point3d centerPt = new Point3d(100, 100, 0);
                    double circleRad = 100.0;
                    using (Circle circle = new Circle())
                        
                    {
                        circle.Radius = circleRad;
                        circle.Center = centerPt;
                        circle.Layer = "ELEV_LIGHT";
                        

                        btr.AppendEntity(circle);
                        trans.AddNewlyCreatedDBObject(circle, true);
                    }
                    trans.Commit();

                }
                catch (System.Exception ex)
                {

                    doc.Editor.WriteMessage("Error encountered: " + ex.Message);
                    trans.Abort();
                }

            }
        }

        [CommandMethod("DRAWMTEXT")]
        public void DrawMText()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor edt = doc.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    edt.WriteMessage("Drawing MText Exercise!");
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;

                    // specify the Mtext parameters
                    string txt = "Hello AutoCAD, from cSharp.";
                    Point3d insPt = new Point3d(200, 200, 0);
                    using (MText mtx = new MText())
                    {
                        mtx.Contents = txt;
                        mtx.Location = insPt;

                        btr.AppendEntity(mtx);
                        trans.AddNewlyCreatedDBObject(mtx, true);
                    }
                    trans.Commit();
                }
                catch (System.Exception ex)
                {

                    edt.WriteMessage("Error encountered: " + ex.Message);
                    trans.Abort();
                }
            }
        }

        [CommandMethod("DRAWLINE")]
        public void DrawLine()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor edt = doc.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTable bt;
                    bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

                    BlockTableRecord btr;
                    btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    // send a message to the user
                    edt.WriteMessage("\nDrawing a Line object");
                    Point3d pt1 = new Point3d(0, 0, 0);
                    Point3d pt2 = new Point3d(100, 100, 0);
                    Line ln = new Line(pt1, pt2);
                    ln.ColorIndex = 8;
                    btr.AppendEntity(ln);
                    trans.AddNewlyCreatedDBObject(ln, true);
                    trans.Commit();

                }
                catch (System.Exception ex)
                {

                    edt.WriteMessage("Error was encountered: " + ex.Message);
                    trans.Abort();
                }
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 01:30:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950433#M8890</guid>
      <dc:creator>Jeremiah.Dillashaw</dc:creator>
      <dc:date>2023-05-09T01:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950483#M8891</link>
      <description>Using...&lt;BR /&gt;[assembly: CommandClass(typeof(DrawObjects.DrawObject)]&lt;BR /&gt;namespace DrawObjects&lt;BR /&gt;{class DrawObject&lt;BR /&gt;...&lt;BR /&gt;}&lt;BR /&gt;}</description>
      <pubDate>Tue, 09 May 2023 02:08:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950483#M8891</guid>
      <dc:creator>cuongtk2</dc:creator>
      <dc:date>2023-05-09T02:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950532#M8892</link>
      <description>&lt;P&gt;I created a new project/solution, added the 3 references, copied your code into the new class, built solution, started C3D, netload assembly, answered to always load, tried drawline command, line created without issue. So it is not your code...do you have anything else in the project?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What version of AutoCAD? Which Visual Studio? What .NET Framework is the project using?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 02:57:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950532#M8892</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2023-05-09T02:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950546#M8893</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6638420"&gt;@cuongtk2&lt;/a&gt; . I tried your suggestion as best as i know how, and i still had the same result of "unknown command".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is just the top few lines of the code, in case i didn't follow your instruction correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;

[assembly: CommandClass(typeof(DrawObjects.DrawObject))]
namespace DrawObjects
{
    class DrawObject
    {

//... didn't want to dump it all in again, nothing below here changed&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 03:16:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950546#M8893</guid>
      <dc:creator>Jeremiah.Dillashaw</dc:creator>
      <dc:date>2023-05-09T03:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950551#M8894</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/32637"&gt;@Jeff_M&lt;/a&gt; , i'm using ACAD 2023, VS 2022 &amp;amp; .net 6.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is nothing else in the visual studio project, if that's what you mean. The class and methods are all wrapped up in one just for size and exercise purposes--i'm guessing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm going through a C# and AutoCAD programming with .NET course on Udemy. I have reached out to the instructor, i just figured it'd be a good idea to cast the net wide &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks for responding.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 03:21:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950551#M8894</guid>
      <dc:creator>Jeremiah.Dillashaw</dc:creator>
      <dc:date>2023-05-09T03:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950564#M8895</link>
      <description>&lt;P&gt;I looked in my acad.exe.config file. There's some supported runtime stuff in there, i don't know if this is related to .net runtime, but it has some "useLegacyV2Runtime..." thing in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible one of my other main ACAD addins changed to this when it installed? I use Microvellum in almost all my daily work with ACAD.&lt;/P&gt;&lt;P&gt;I'm just guessing of course. Here's the config file contents though:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;configuration&amp;gt;
 &amp;lt;startup useLegacyV2RuntimeActivationPolicy="true"&amp;gt;
   &amp;lt;supportedRuntime version="v4.0"/&amp;gt;
   &amp;lt;supportedRuntime version="v2.0.50727" /&amp;gt;
 &amp;lt;/startup&amp;gt;
 &amp;lt;runtime&amp;gt;        
   &amp;lt;generatePublisherEvidence enabled="false"/&amp;gt;    
 &amp;lt;/runtime&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 03:33:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950564#M8895</guid>
      <dc:creator>Jeremiah.Dillashaw</dc:creator>
      <dc:date>2023-05-09T03:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950573#M8896</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6314467"&gt;@Jeremiah.Dillashaw&lt;/a&gt;&amp;nbsp;your project must be a .NET Framework not a .NET 6.0 assembly. I'm on my phone so cannot post an image, sorry.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 03:45:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950573#M8896</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2023-05-09T03:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950581#M8897</link>
      <description>&lt;P&gt;You CANNOT use .NET Core (.NET5/6/7). AutoCAD .NET API project can only work with .NET Framework (since you use Acad2023, thus .NET Framework 4.8x)!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, make sure you choose your VS2022 project type correctly: &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Class Library (.NET Framework), &lt;/STRONG&gt;&lt;FONT color="#000000"&gt;not&lt;/FONT&gt;&lt;STRONG&gt; Class Library &lt;/STRONG&gt;&lt;FONT color="#000000"&gt;(which creates .NET Core class library)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 03:54:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950581#M8897</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2023-05-09T03:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to load an assembly properly.</title>
      <link>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950594#M8898</link>
      <description>&lt;P&gt;Thank you very much guys. It's all straitened out now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Everything is working as expected, once i got the correct project type selected. I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 04:09:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/unable-to-load-an-assembly-properly/m-p/11950594#M8898</guid>
      <dc:creator>Jeremiah.Dillashaw</dc:creator>
      <dc:date>2023-05-09T04:09:08Z</dc:date>
    </item>
  </channel>
</rss>

