Await in Oxygene

I have written a Hydra-module in Oxygene which uses an external API. The authorization routine of the API has been changed, and i can’t get the new routine to work.
This is an example of C# code that are given as an example from the makers of the API:

// Main method for C# 7.1 and above
public static async Task Main(string[] args)
{
await RunDemo();
}

    /// <summary>
    ///     The purpose of this demo is to show how projects can be created and queried.
    /// </summary>
    private static async Task RunDemo()
    {
        try
        {
            // Set up authorization settings
            var authorizationSettings = new AuthorizationSettings
            {
                ApplicationKey = "<You Application Key Here>",
                ClientKey = "<PowerOffice Go Client Key Here>",
                TokenStore = new BasicTokenStore(@"my.tokenstore"),
                EndPointHost = Settings.EndPointMode.Production 
            };

            // Initialize the PowerOffice Go API and request authorization
            var api = await Go.CreateAsync(authorizationSettings);

My last line in Oxygene is:
var api := await Go.CreateAsync(authorizationSettings);

This is where my program stops. It looks like it awaiting forever.

My questions are:
Does await have the same meaning in Oxygene as in C#?

Do i have to declare the procedure where this line is in a special way?
The C# procedure is declared as: public static async Task

I’m using Water to compile the module. Would it be different with Visual Studio?

Best regards
Geir Harald Humstad

It should work with public static Task, the async isnt needed

1 Like

I took one of the example programs provided and translated into Oxygene with Oxydizer.
Here is the C# program that works:

using System;
using System.Threading.Tasks;
using GoApi;
using GoApi.Core;
using GoApi.Core.Global;

namespace AuthorizationDemo
{
internal class Program
{

    // Main method for C# 7.1 and above
    public static async Task Main(string[] args)
    {
        await RunDemo();
    }

    //// Main method for C# 7.0 and below. Be careful with Wait, you can get deadlocks. It is highly recommended to update to C# 7.1 for console applications.
    //// To change the C# version, open the project properties, go to Build, then click the Advanced button in the bottom right, and select your C# version.
    //// If you can't find an appropriate C# version you may need to update your Visual Studio.
    //public static void Main(string[] args)
    //{
    //    RunDemo().Wait();
    //}

    /// <summary>
    ///     The purpose of this demo is to test if the PowerOffice Go Authentication server will allow us
    ///     to be authorized to access the PowerOffice GO API.
    /// </summary>
    private static async Task RunDemo()
    {
        try
        {
            // Create authorization settings for the test client
            Console.WriteLine("Setting up authorization settings..");
            // Set up authorization settings
            var authorizationSettings = new AuthorizationSettings
            {
                ApplicationKey = "",
                ClientKey = "",
                TokenStore = new BasicTokenStore(@"my.tokenstore"),
                EndPointHost = Settings.EndPointMode.Production 
            };

            // Request authorization from the PowerOffice GO authentication server
            Console.WriteLine("Requesting authorization..");
            var api = await Go.CreateAsync(authorizationSettings);

            // If no exceptions is thrown by now, we have sucessfully been authorized to access the PowerOffice GO API
            Console.WriteLine("Authorization granted!");
        }
        catch (ApiException e)
        {
            Console.WriteLine("Error: " + e.Message);
        }

        // Wait for user input
        Console.WriteLine("\n\nPress any key...");
        Console.ReadKey();        
    }
}

}

Here is the Oxygene program that don’t work:

namespace ConsoleApplication1;

interface

uses
System,
System.Threading.Tasks,
GoApi,
GoApi.Core,
GoApi.Core.Global;

type
Program = assembly class
private
class method RunDemo: Task;
public
// Main method for C# 7.1 and above
class method Main(args: array of String): Task;
end;

implementation

class method Program.Main(args: array of String): Task;
begin
await RunDemo();
//RunDemo.Wait;
end;

class method Program.RunDemo: Task;
begin
try
// Create authorization settings for the test client
Console.WriteLine(‘Setting up authorization settings…’);
// Set up authorization settings
var authorizationSettings := new AuthorizationSettings(
ApplicationKey := ’ ',
ClientKey := ’ ',
TokenStore := new BasicTokenStore(‘my.tokenstore’),
EndPointHost := Settings.EndPointMode.Production);

//  Request authorization from the PowerOffice GO authentication server
Console.WriteLine('Requesting authorization..');
var api := await Go.CreateAsync(authorizationSettings);
//  If no exceptions is thrown by now, we have sucessfully been authorized to access the PowerOffice GO API
Console.WriteLine('Authorization granted!');

except
on e: ApiException do begin
Console.WriteLine(‘Error: ’ + e.Message);
end;
end;
// Wait for user input
Console.WriteLine(#10#10’Press any key…’);
Console.ReadKey();
end;
end.

Is there someone who can spot the error in the Oxygene-code?
And is Oxygene at the level of C# 7.1 or is it below?

Best regards
Geir Harald Humstad

It looks ok, whats the output ?

The output is nothing. Even the first console.writeline is not shown.

can you zip up the project and attach it to a message ?