How do you include a class in BPM C# code?

Given the following snippet of code I’m getting an error in the editor:

So I think I know at a high level what that means. But I don’t understand how to “include” something.
I believe this may be the class I want to use: WebHeaderCollection Class (System.Net) | Microsoft Learn Is that some class that anyone can use anytime?

This is really basic but how do you include something, like literally what buttons on the Epicor interface do that? Where do I put the code to include? What does the code look like that I must include to allow me to use this class, or really any other class I find? Usings and includes is scary atm, I have no examples to work from and don’t know the syntax. I tried both using and references but I’m stuck.

What I’m doing is calling an API I created and it’s not doing what I expect so I want to troubleshoot by seeing what my endpoint is returning by popping open up a message box when the rest call is finished. My endpoint works in POSTMAN just fine so I want to see what Epicor is doing with it.

You need to add the reference with the References tab, then type

using YourReferenceLib;

in the using statements

image

image

Also I doubt you’re going to be able to use .NET 5.0 libraries unless your server is running .NET 5.0, so you’re better off targeting libraries that are in the 4.8+ or lower packages

1 Like

Is assemblies a fancy way to say .dll?

Does the grayed out Add/Remove mean they are always loaded?

image

So according to that webheadercollection is part of system in .net 4.8, which is always loaded? So is the error saying I’m missing the assembly wrong? Or am I just not declaring it out of the system in my C# code?

Or does that mean system.net has a lot of different classes inside it and if I want to use a particular class from system.net I have to type using Name.Of.Class on the using page?

They’re just not magically available whenever?

Yes assemblies = dll. Some are pre-loaded, just gotta play around with it

It’s not magically available but you might be able to use it by declaring your variable like:

System.Net.WebHeaderCollection myWebHeaderCollection = ...
1 Like

Namespaces help organize and isolate classes, to instantiate a class you need to include the namespace(as well as reference the assembly). A using statement is an alternative to fully qualifying the class and namespace every time you instantiate. You can have two classes named the same thing, in this case you would need to use the fully qualified namespace to differentiate the two.
Also, using statements can be used to control how many of the classes in an assembly are actually loaded at runtime.

2 Likes

To answer your specific question, you would add
using System.Net;

Or, as Mark suggested, use the namespace when you create an instance.