0

I'm trying to make a function with c# with fn project, I did this job with an Dockerized linux containerized API with Visual Studio 2022 and it works great.

The problem is, when I try to make the same with fn on a VM with Centos 9 it doesn't work and I dont know how to view the errors/exceptions. The only message I get is:

{"message": "error receiving function response"}

I modify my Dockerfile like next

FROM fnproject/dotnet:6.0-1.0.9-dev as build-stage
WORKDIR /function
COPY . .

RUN dotnet sln add src/Function/Function.csproj
RUN dotnet build -c Release
RUN dotnet publish src/Function/Function.csproj -c Release -o out

FROM fnproject/dotnet:6.0-1.0.9

WORKDIR /function
COPY --from=build-stage /function/out/ /function/
ENTRYPOINT ["dotnet", "Function.dll"]
CMD ["Function:Encoder:encode"]

And I show my func.yaml

schema_version: 20180708
name: encode-image
version: 0.0.133
runtime: dotnet6.0
build_image: fnproject/dotnet:6.0-1.0.9-dev
run_image: fnproject/dotnet:6.0-1.0.9
cmd: Function:Encoder:encode
entrypoint: dotnet Function.dll
memory: 2048
timeout: 300
triggers:
- name: encode-image
  type: http
  source: /api/v1/encode-image

And my Function.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <!--Nullable>enable</Nullable-->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Fnproject.Fn.Fdk" Version="1.0.9" />
    <PackageReference Include="DlibDotNet" Version="19.21.0.20220724" />
    <PackageReference Include="DlibDotNet.Extensions" Version="19.18.0.20200428" />
    <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="12.2.2" />
    <PackageReference Include="Magick.NET.Core" Version="12.2.2" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
  </ItemGroup>

  <ItemGroup>
    <None Update="Assets\dlib\dlib_face_recognition_resnet_model_v1.dat">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Assets\dlib\shape_predictor_5_face_landmarks.dat">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

I was trying to focus the code which generates the problem and I think is related with next:

detector = Dlib.GetFrontalFaceDetector();
shapePredictor = ShapePredictor.Deserialize("Assets/dlib/shape_predictor_5_face_landmarks.dat");
net = DlibDotNet.Dnn.LossMetric.Deserialize("Assets/dlib/dlib_face_recognition_resnet_model_v1.dat");

And when I call the function with Postman I get: Postman showing error

Dont know how to discover the problem. I think is realted to the load of .dat files or some time the fn framework waits or I dont know.

At last, my method which is called:

public string encode(string strRequest)
{
    // Lets generate basic response
    Dictionary<string, object> mapResponse = new Dictionary<string, object>();
    //List<string> lstErrors = new List<string>();
    try
    {
        JObject jsonRequest = new JObject();
        jsonRequest = JObject.Parse(strRequest);
        // Lets validate options from request
        Dictionary<string, object> mapRequest = validateParameters(jsonRequest);
        // Lets get valid parameters
        Dictionary<string, object> mapParameters = (Dictionary<string, object>)mapRequest["parameters"];
        // If debug mode is true, then add debug info
        if (((bool)mapParameters["debug"]) == true) mapResponse["debugging"] = mapParameters;
        // Lets form the response
        mapResponse["errors"] = mapRequest["errors"];
        mapResponse["result"] = string.Empty;
        // If there are not errors with parameters and their values then calculate encoding
        if (((List<string>) mapRequest["errors"]).Count == 0)
        {
            // Thinking in future updates, we are going to use a factory
            IEncoder encoder = EncoderFactory.createEncoder((string)mapParameters["algorithm"]);
            // Lets add the resulting object to the response
            mapResponse["result"] = encoder.Encode(mapParameters);
            //if(((Encoder_FaceRecognition) encoder).resourceLoaded==true) return "OK";
            //return "NOK";
        }
    }
    catch (System.Exception exception)
    {
        ((List<string>)mapResponse["errors"]).Insert(0, "<ERROR> Some exception has occurred." + exception.StackTrace);
        ((List<string>)mapResponse["errors"]).Insert(0, "<ERROR> Some exception has occurred." + exception.Message);

    }
    return "<EXITO>";
    //return JsonConvert.SerializeObject( mapResponse );
}
Yury Euceda
  • 570
  • 4
  • 15

0 Answers0