Closed har07 closed 4 years ago
Hi @har07 , with the runtime update to .NET Core 3.1 all synchronous code has been migrated to async to be compliant with the new ASP.NET Core 3 directive that discourages the usage of synchronous operations (https://docs.microsoft.com/en-us/dotnet/core/compatibility/2.2-3.0#http-synchronous-io-disabled-in-all-servers)
so your example should become (I didn't tested the code):
using System;
using Kubeless.Functions;
public class module
{
public async Task<string> handler(Event k8Event, Context k8Context)
{
string plantID = "XXX";
return plantID;
}
}
Try this and tell me if you have any error ;)
Hi @lorenzo-ange, thanks for responding. I just tried using async Task<string>
and added using System.Threading.Tasks;
:
using System;
using System.Threading.Tasks;
using Kubeless.Functions;
public class module
{
public async Task<string> handler(Event k8Event, Context k8Context)
{
string plantID = "XXX";
return plantID;
}
}
now I got a different error:
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://testkedatabase/
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Kubeless.WebAPI.Controllers.RuntimeController.Execute (Kubeless.WebAPI)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "Execute", controller = "Runtime"}. Executing controller action with signature System.Threading.Tasks.Task`1[System.Object] Execute() on controller Kubeless.WebAPI.Controllers.RuntimeController (Kubeless.WebAPI).
info: Kubeless.WebAPI.Controllers.RuntimeController[0]
04/30/2020 09:28:30: Function Started. HTTP Method: GET, Path: /.
crit: Kubeless.WebAPI.Controllers.RuntimeController[0]
04/30/2020 09:28:30: Function Corrupted. HTTP Response: 500. Reason: Cannot implicitly convert type 'System.Threading.Tasks.Task<string>' to 'System.Threading.Tasks.Task<object>'.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot implicitly convert type 'System.Threading.Tasks.Task<string>' to 'System.Threading.Tasks.Task<object>'
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Kubeless.Core.Invokers.CompiledFunctionInvoker.Execute(Event kubelessEvent, Context kubelessContext) in /app/Kubeless.Core/Invokers/CompiledFunctionInvoker.cs:line 49
at Kubeless.WebAPI.Controllers.RuntimeController.Execute() in /app/Kubeless.WebAPI/Controllers/RuntimeController.cs:line 43
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ProblemDetails'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action Kubeless.WebAPI.Controllers.RuntimeController.Execute (Kubeless.WebAPI) in 136.4651ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Kubeless.WebAPI.Controllers.RuntimeController.Execute (Kubeless.WebAPI)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 152.9551ms 500 application/problem+json; charset=utf-8
Now it works. Following the error message, I changed the function return type from Task<string>
to Task<object>
:
using System;
using System.Threading.Tasks;
using Kubeless.Functions;
public class module
{
public async Task<object> handler(Event k8Event, Context k8Context)
{
string plantID = "XXX";
return plantID;
}
}
I'm closing this issue. Thanks for your explanation @lorenzo-ange
As the title said, I got error "
Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<object>'
" when trying a simple function using dotnetcore 3.1 runtime. Here is the function log:function:
csproj: