Can Revit API Access any .dll of the .net framework for External Comands?

Can Revit API Access any .dll of the .net framework for External Comands?

eduardooost
Participant Participant
1,617 Views
8 Replies
Message 1 of 9

Can Revit API Access any .dll of the .net framework for External Comands?

eduardooost
Participant
Participant

How can I load any .NET class from a RevitAPI external command? I'm constantly getting this error even after adding a reference to the .dll file in the .csproj file: "Could not load "System.Globalization" from "System.Runtime" assembly" version 4.0.0.0"".

0 Likes
Accepted solutions (1)
1,618 Views
8 Replies
Replies (8)
Message 2 of 9

jeremy_tammik
Alumni
Alumni
Accepted solution

Yes, a Revit add-in can make use of all the standard .NET library assembly DLLs.

    

You must be doing something special to cause a problem like that.

    

Obviously I cannot guess what you might be doing wrong.

    

If in doubt, I would recommend throwing away all your problematic stuff for the time being and starting from scratch.

    

Normally, the problem should immediately disappear. 

  

Then you can add back you problematic components piece by piece until the problem reappears. 

  

That might help you sort out what is causing it.

  

Good luck sorting it out.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 9

GaryOrrMBI
Collaborator
Collaborator
I don't know which version of Revit you're developing for but Revit versions are dependent upon different versions of the .NET library.

I notice that your post says version 4.0.0 of the runtime...

From the 2023 "Getting Started..."
The Autodesk Revit API requires the Microsoft .NET Framework v4.8.
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 4 of 9

eduardooost
Participant
Participant

Thanks for the response. I was coding and compiling my class library from .NET CLI. Therefore the .CSPROJ file lacks many of the components that a default Visual Studio .CSPROJ automatically generated file brings. I would like to continue learning to create external commands and external applications in .NET CLI, but this entails knowledge of MSBUILD and other elements. But so far, I can reach .NET dlls trough the default class library project that Visual Studio generates. Thank you!

Message 5 of 9

eduardooost
Participant
Participant

Thanks also for your response Gary.

 

I'm publishing my external command through .NET CLI with "win-x64" as the runtime option, and .NET6.0 as the framework option.

 

But when I browse to the location of the dlls in my computer, I find that they are located on this folder: "C:\Windows\Microsoft.NET\Framework64\v4.0.30319". 

 

I don't know if this is the "4.0.0.0" version

AutodeskForumLoadDllError.PNG

that the error message displays.

 

 

 

 

Message 6 of 9

sayu94
Enthusiast
Enthusiast
Hello. may be you use another dll libraries for revit and another net framework for your revit version?
Message 7 of 9

GaryOrrMBI
Collaborator
Collaborator

I believe that the installed .NET assemblies (for development and what should be referenced and/or included) are found here:  

 

GaryOrrMBI_0-1679929226210.png

 

GaryOrrMBI_1-1679929715869.png

Of course, all of this could just be because I'm using Visual Studio and these may just be installed and referenced by default because of that, but I believe that this is also the structure that is created if you install a given version of the .NET libraries from Microsoft.

 

-G

 

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 8 of 9

NGM_AiYo
Advocate
Advocate
                string location = Assembly.GetExecutingAssembly().Location;
                DirectoryInfo directory = new DirectoryInfo(location);
                
                var pathTmp = directory.Parent.FullName + "\\Microsoft.Xaml.Behaviors.dll";
                if (File.Exists(pathTmp))
                {
                    Assembly.LoadFrom(pathTmp);
                }

Change the  dll name to yours,  at the start of execution.

I have met same question,  dll is not load automatically.

Don't know why.

0 Likes
Message 9 of 9

mhannonQ65N2
Collaborator
Collaborator
You should not be using .NET6.0 at all. Revit addins must use the specified version of the .NET Framework (for Revit 2021, 2022, and 2023 it is .NET Framework 4.8).
0 Likes