locked
Tasks asynchronously - doesnt run on win server 2008, IIS 7.5 RRS feed

  • Question

  • User360451555 posted

    Hi, i have an ASP.NET Web API that is running well on my dev machine (Win 10, IIS Express, VS 2017) When i configure the API to run on the win server 2008, IIS 7.5, i get errors pointing to the points where am running some asynchronous code. Here is how am running the code. 

    i have a service. 

    public Task<List<string>> GetLabelVariablesAsync(string labelFileName, CancellationToken token)
    {
        var path = HttpContext.Current.Request.MapPath($"~\\Labels\\{labelFileName}.nlbl");
    
        var label = Task.Run(() =>  PrintEngineFactory.PrintEngine.OpenLabel(path), token);
    
        var variableNames = label.Result.Variables.Select(labelVariable => labelVariable.Name).ToList();
    
        return Task.FromResult(variableNames);
    }

    then in my controller, i use it like this

    [HttpGet]
    public async Task<IHttpActionResult> Get()
    {
        var label = new LabelService();
        var source = new CancellationTokenSource();
    
        var labelVariables = await label.GetLabelVariablesAsync("Label_40x300mm", source.Token).ConfigureAwait(false);
    
        if (labelVariables == null)
        {
            return NotFound();
        }
        return Ok(labelVariables);
    }

    This code returns the expected results but however, on a Win Server 2k8, i get a big fat stacktrace pointing to System.AggregateException. 

    "Message":"An error has occurred.","ExceptionMessage":"One or more errors occurred.","ExceptionType":"System.AggregateException","StackTrace":" at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\r\n at PrintAPI.Services.LabelService.GetLabelVariablesAsync(String labelFileName)

    Am i supposed to configure server 2k8 to run asynchronous code? or what on earth am i doing wrong?

    Tuesday, January 22, 2019 9:22 AM

Answers

  • User-474980206 posted

    while Task.Run is useless the way its used, its probably not the error. the error is probably the PrintEngine is not correctly configured on the server (generally they use a profile, which will not be defined for a service account).

       

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 4:14 PM
  • User753101303 posted

    Hi,

    Or check the inner exception(s) or use https://docs.microsoft.com/en-us/dotnet/api/system.aggregateexception.handle?view=netframework-4.7.2 to see first which exact exception happens. It should take a couple of minutes but at least you'll start knowing which problem happens rather than tyring to guess.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 5:10 PM
  • User36583972 posted


    Hi feiyim,

    Hi, i have an ASP.NET Web API that is running well on my dev machine (Win 10, IIS Express, VS 2017) When i configure the API to run on the win server 2008, IIS 7.5, i get errors pointing to the points where am running some asynchronous code. Here is how am running the code. 

    i have a service. 

    C# 5 introduced a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and higher.

    You can try to check whether the the .NET Framework 4.5 and higher package have installed on the win server 2008, IIS 7.5.

    Asynchronous programming with async and await (C#)
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/


    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 23, 2019 2:09 AM

All replies

  • User475983607 posted

    This code is causing the problem.  You are spinning up a new thread and calling a synchronous method.  The code is not starting a background thread.  Remove the async code as you are really making the code less efficient.

    var label = Task.Run(() =>  PrintEngineFactory.PrintEngine.OpenLabel(path), token);
    
    var variableNames = label.Result.Variables.Select(labelVariable => labelVariable.Name).ToList();

    https://blog.stephencleary.com/2013/11/taskrun-etiquette-examples-dont-use.html

    Tuesday, January 22, 2019 11:35 AM
  • User-474980206 posted

    while Task.Run is useless the way its used, its probably not the error. the error is probably the PrintEngine is not correctly configured on the server (generally they use a profile, which will not be defined for a service account).

       

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 4:14 PM
  • User753101303 posted

    Hi,

    Or check the inner exception(s) or use https://docs.microsoft.com/en-us/dotnet/api/system.aggregateexception.handle?view=netframework-4.7.2 to see first which exact exception happens. It should take a couple of minutes but at least you'll start knowing which problem happens rather than tyring to guess.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 22, 2019 5:10 PM
  • User36583972 posted


    Hi feiyim,

    Hi, i have an ASP.NET Web API that is running well on my dev machine (Win 10, IIS Express, VS 2017) When i configure the API to run on the win server 2008, IIS 7.5, i get errors pointing to the points where am running some asynchronous code. Here is how am running the code. 

    i have a service. 

    C# 5 introduced a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and higher.

    You can try to check whether the the .NET Framework 4.5 and higher package have installed on the win server 2008, IIS 7.5.

    Asynchronous programming with async and await (C#)
    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/


    Best Regards,

    Yong Lu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 23, 2019 2:09 AM