Error executing method from dll

I am trying to execute a dll Method, compiled in visual studio, from FranworkX, but I get the following error:

Task_Revisa_Listas.UserControl1 SetTask ;

public async Task Main()
{
bool Result = false;
try{
SetTask = new Task_Revisa_Listas.UserControl1();

bool Resultx  =  SetTask.Start_Funcion_Principal();
@Info.Trace("Funcion de inicio ejecutada correctamente");
Result = true;

}catch(Exception e){

@Info.Trace(“La funcion no se ejecuto Correctamente” + e.Message);
Result = false;
}
}

This is a simple example code to execute that method:

Hi Javier,
Was this DLL successfully imported into FrameworX?
You can check this by going to Scripts / References, importing the DLL, and then clicking “Verify References.”
If it was imported successfully, could you send the error message you encountered when running the code?

Good day, yes, I attach an image where you can see that if I load the dll correctly.

What we are looking for is that this function is executed by the server and not the clients, I have observed that if I run the function from a display if it runs, but when I try to put it in a Task(ServerStartup) we mark the error, which I shared with you.

Attached error message, it is being captured with a try-catch

The “The calling thread must be STA, because many UI elements require this” error indicates that the called function is using a UI framework such as WPF or Windows Forms, where certain objects (like dialogs, message boxes, or some COM components) require the thread to be STA (Single-Threaded Apartment)

In general, UI interactions should not be handled in server-side functions, as this is considered poor programming practice. Server-side tasks are typically designed to run in a non-UI (background) context.

However, if it’s absolutely necessary to invoke a UI-related method from a server-side context (not recommended), you can work around the error using an STA thread like this:

System.Threading.Thread staThread = new System.Threading.Thread(() =>
{
    //Call the UI-related method here
    YourMethodThatNeedsSTA();
});
staThread.SetApartmentState(System.Threading.ApartmentState.STA);
staThread.Start();
staThread.Join();

That said, this is a long shot — I can’t say for sure whether it will work in your case because I don’t have access to the specific DLL or component you’re using. If this workaround doesn’t resolve the issue, I recommend reaching out to FrameworX support, as they’ll be able to provide a more specialized assistance.