GetHostName in Inventor 2025

GetHostName in Inventor 2025

JBerns
Advisor Advisor
347 Views
13 Replies
Message 1 of 14

GetHostName in Inventor 2025

JBerns
Advisor
Advisor

Community,

 

In many Inventor 2022 rules, I used this code posted by Clint Brown:

 

' Get Computer Name
Dim oPCName As String = System.Net.Dns.GetHostName()

 

https://clintbrown.co.uk/2021/01/06/ilogic-quick-tip-get-ip-address/ 

 

 

Now when I run any of these rules in Inventor 2025, the following error occurs:

 

Error on Line 7 : 'Dns' is not a member of 'System.Net'.

 

I have searched the forums and other resources, but have not found a solution. Your assistance please.

 

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (2)
348 Views
13 Replies
Replies (13)
Message 2 of 14

JBerns
Advisor
Advisor

After more research of .NET 8, I discovered this code works:

oPCName = System.Environment.MachineName

I hope it benefits others.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 3 of 14

WCrihfield
Mentor
Mentor

My initial guess is that it may require 'AddReference' type lines in the 'Header', if using it from iLogic rules.  The 2025 and later versions seem to be stricter than the earlier versions on stuff like that.

The online documentation mentions two DLL files.

netstandard.dll

System.Net.NameResolution.dll

...but just guessing, since I do not use that resource myself regularly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 14

jjstr8
Collaborator
Collaborator

Although I'm still on 2024, but I believe @WCrihfield is correct. I couldn't see any other reason why it didn't work. Did Intellisense not prompt you through the namespaces? Also note that GetHostByName is deprecated and you should use GetHostEntry instead. It returns the same IPHostEntry object, so it's pretty painless to switch.

 

jjstr8_0-1747683447399.png

 

0 Likes
Message 5 of 14

JBerns
Advisor
Advisor

@jjstr8,

 

In Inventor 2025.2.1, the Intellisense offered WebUtility after .Net.

 

JBerns_0-1747688278638.png

 

I thought the .Net 8 changes would effect add-ins, not iLogic rules.

 

Perhaps there are DLLs that I could include, but the code above is working well to get the PC name.

 

Thanks @jjstr8. Thanks @WCrihfield

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 6 of 14

jjstr8
Collaborator
Collaborator

@JBerns : You may want to keep investigating or report this as a bug. I'm noticing that you don't have the Types or Namespaces filter buttons at the bottom of the Intellisense popup. You may keep running into issues with other rules you make.

0 Likes
Message 7 of 14

WCrihfield
Mentor
Mentor

Yep.  I am also currently using 2024.3.4 at work, and when I open a new iLogic rule, with nothing in its header, and type in "System.Net.", I get a super long, scrolling list with around 68 entries in it, the last of which is the 'WebUtility', which appears to be the only one in your screen shot.  That tells me the differences between 2024 version and 2025 versions of Inventor definitely has an effect on our iLogic rules.  Maybe the 'WebUtility' is the only one in that list that iLogic is including the 'reference' for us automatically.  I don't think it is possible that the 'WebUtility' is the only one in that list that is VB.NET 8 compliant.  I use System.Net.Mail to create new emails in MS Outlook, for sending exported files to outsource fabricators/suppliers.  Often 'Namespace' documentation does not indicate coding system compliance, but usually top level members within it will.  In this case the System.Net.Mail.MailMessage is definitely indicating that it is compliant with .Net, .Net Framework, & .Net Standard, so its Namespace, and any parent Namespaces must be accessible too.

Below is a similar screen shot from my system.  You can see that the scroll bar within that list is pretty small, indicating a lot of stuff to scroll through.  Also showing the 'filters' at the bottom of that context menu that @jjstr8 mentioned.  Maybe they eliminated that in 2025, not sure.  Another possibility is that we see different things there due to whether we have Visual Studio installed, and what version...and maybe if we have the Inventor SDK stuff installed (Developers Tools & User Tools).  Not sure there either, but something to consider.  For reference, I do have them installed.

WCrihfield_0-1747740460581.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 14

JBerns
Advisor
Advisor

Whether the filters are enabled or disabled, the only option is 'WebUtility' after typing "System.Net." in the Inv2025 iLogic Editor.

 

I used a standard installation of Inventor from the Autodesk Manage site.

Do you think this is a bug?

 

Same result when I test in Inventor 2026.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 9 of 14

WCrihfield
Mentor
Mentor
  • Do you have Visual Studio installed?
    • If so, what version?
    • Not sure if version matters, so just for documentation / observation / research.
  • Have you installed the Inventor SDK stuff that comes with Inventor 2025 yet?

This is just a theory about explaining this difference in behavior, as mentioned before, but maybe having these additional things installed locally influences what we see in those 'Intellisense' lists in our iLogic rules.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 14

JBerns
Advisor
Advisor

Visual Studio 2022 installed. Version 17.13.7

I did not have the Inv 2025 SDK installed when testing above.

I installed the SDKs, restarted, same result of limitation to WebUtility only when typing "System.Net.".

 

I know my 2022 rules worked on other workstations that did not have VS or the SDKs installed, so that is why I did not think it was an SDK requirement.

This is going to be a lot of code editing to get 2022 rules compatible with changes in 2025.

 

Wes, perhaps you could test some of your rules containing "System.Net" on the Autodesk Beta site, 'Run in Browser'.

 

Perhaps Mike ( @MjDeck ) can offer some explanation.

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 11 of 14

jjstr8
Collaborator
Collaborator

@JBerns : Thanks for the video. I poked around and found out that the filter buttons are only there if the list isn't exclusively Types or exclusively Namespaces, which is what you're seeing. I still think this is bug. iLogic always seemed like a "universally accessible" feature, allowing any user to program different capabilities without requiring something like Visual Studio or an SDK.

 

I did check the online help for 2024 & 2025 regarding the default Imports. They're the same.

  • Imports System
  • Imports System.Math
  • Imports System.Collections
  • Imports Microsoft.VisualBasic
  • Imports Autodesk.iLogic.Interfaces
  • Imports Autodesk.iLogic.Runtime

"System" is a default import, but I'm going to assume that the result is the same if you don't fully qualify the namespace.

jjstr8_0-1747752743962.png

 

0 Likes
Message 12 of 14

MjDeck
Autodesk
Autodesk

@JBerns - the move to .NET 8 in Inventor 2025 does affect iLogic rules. Everything compiles and runs on .NET 8. We tried to make it as transparent as possible, but there are significant changes in the underlying system. If you use System methods in your code, you might have to add new AddReference statements or use a different function.
In this case, you found System.Environment.MachineName.

Please let me know if you find more compile errors related to System types or functions.


Mike Deck
Software Developer
Autodesk, Inc.

Message 13 of 14

MjDeck
Autodesk
Autodesk
Accepted solution

Here are the required AddReference statements in this case. @WCrihfield mentioned these above.

AddReference "netstandard.dll"
AddReference "System.Net.NameResolution.dll"

Dim oPCName As String = System.Net.Dns.GetHostName()
Logger.Info("PC name = {0}", oPCName)

Dim otherMethodName = System.Environment.MachineName
Logger.Info("PC name = {0}", otherMethodName)


You can get the required DLL names from the .NET help page for this function.


Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 14

MjDeck
Autodesk
Autodesk
Accepted solution

Here's a new version of the rule from 
https://clintbrown.co.uk/2021/01/06/ilogic-quick-tip-get-ip-address/

AddReference "netstandard.dll"
AddReference "System.Net.NameResolution.dll"
AddReference "System.Net.Primitives"

'iLogic code by @ClintBrown3D, https://clintbrown.co.uk/ilogic-quick-tip-get-ip-address
'Get Computer Name
Dim oPCName = System.Net.Dns.GetHostName()

'Get IP Adress (IPv4 or IPv6)
'Dim oIPAddress As String = System.Net.Dns.GetHostEntry(oPCName).AddressList.FirstOrDefault.ToString()

' Get IP Address (IPv4 only)
Dim oIPAddress As String = System.Net.Dns.GetHostEntry(oPCName).AddressList _
    .FirstOrDefault(Function(ip) ip.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork) ? .ToString()
	
'Display Message box
MessageBox.Show("PC Name -> " & oPCName & vbNewLine & "IP Address -> " & oIPAddress, "@ClintBrown3D")

'Copy IP address to clipboard
Clipboard.SetText(oIPAddress)

Mike Deck
Software Developer
Autodesk, Inc.