Plugin dll file will netload but not run

Plugin dll file will netload but not run

ajehresmann
Contributor Contributor
2,153 Views
2 Replies
Message 1 of 3

Plugin dll file will netload but not run

ajehresmann
Contributor
Contributor

I'm trying to write my first autocad plugin that's just a basic hello world style program that prints a string to the autocad command line but I can't get it to run and actually print the string. Netload seems to work because the name of the command appears in the command prediction menu that pops up when you start typing but when I select it nothing then happens. I think the problem is that my project targets the .NET 4.8 version and the computer I'm trying to run it on only has the 5.0 runtime installed, but to change what's installed on the later computer I need permission so I want to make sure I know what the problem is before I ask. And also when I tried to re-target my program to the 5.0 runtime it threw error codes at me that I think meant that my code won't work with that .NET version so I'm not sure if maybe I could successfully re-target my program somehow. I tried search for a solution like restoring NuGet packages but that didn't work. My current project targets .NET 4.8 and I'm trying to run it in Autocad 2021 and the machine I'm trying to run it on has a win10 enterprise OS and has the .NET 5.0.17(x64) runtime installed. And my dll doesn't display a security warning that it's been blocked in it's general properties so since it netloads but doesn't run I'm thinking it's because of the framework discrepancy but I'm not completely sure so I've attached my project files and if anyone can lend me a helping hand getting this code to run I'd really appreciate it. And I know the database object isn't used anywhere but I'm planning on using it in a future program and it got leftover and I don't think it could be causing the problem unless I'm mistake. And I know I could implement this easier with LISP but I want to learn how to use .NET for cad so I'm trying to crack this problem. And the computer I'm trying to run the program on requires admin permissions to download most things so I didn't download screencast but I made a recording of the program loading but not doing anything and uploaded it to youtube. This is the link: https://www.youtube.com/watch?v=9-oUES7qqN4

 

using System;
using System.Net.Http;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace HelloAutocad
{
    public class Class1
    {
        [CommandMethod("HelloAutocad")]
        public void HelloAutocadFromCSharp()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor edt = doc.Editor;

            edt.WriteMessage("\nHello Autocad from C#!\n");
        }
    }
 }

Thanks in advance for reading this and any help you can offer.

0 Likes
Accepted solutions (1)
2,154 Views
2 Replies
Replies (2)
Message 2 of 3

kerry_w_brown
Mentor
Mentor

 

The AutoCAD install for ac2021 will install Framework 4.8 if needed on the target machine.

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...

 

The only thing I'd do different is add the following before the local namespace declaretion.

[assembly: CommandClass(typeof(HelloAutocad.Class1))]

 

I can't see any reason that command won't work as you expect.


// Called Kerry or kdub in my other life.

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

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 3 of 3

Norman_Yuan
Mentor
Mentor
Accepted solution

AutoCAD .NET API development can only use .NET framework 4.xxx (should be 4.8 for latest a few versions). .NET Framework and .NET 5/6 are different things. If the computer has AutoCAD installed, the .NET Framework is installed (because AutoCAD requires it). So, the fact that your computer has .NET 5 installed or not should not have anything to do with your issue.

 

As I can see, you probably started the project with WRONG project template in Visual Studio (2022, I suppose), because for .NET framework class library project, the node underneath the project node in the solution window should be "References", not "Dependencies", which should ONLY be there for .NET standard or .NET core (e.g. .NET 5/6).

 

So, try to recreate your class library project: make sure you CHOOSE "Class Library (.NET Framework)", NOT "Class Library"!

Norman Yuan

Drive CAD With Code

EESignature