I am running a dotnet core 2.2 web api on openshift, i have an api method the returns a FileResult. The file is generated using epplus. However after containerizing the application the endpoint returns the below error. I believe this exception occurs if the system.drawing library is used, however i am not using any system.drawing functionality.
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
public async Task<FileResult> GetPSACostCaseAndFeedData([FromQuery] int caseId, [FromQuery] int proposalId, [FromQuery] int equipmentId)
{
try
{
var queryParams = new Dictionary<string, string> { { "caseId", caseId.ToString() }, { "proposalId", proposalId.ToString() }, { "equipmentId", equipmentId.ToString() } };
var restObj = _restFactory.createRestRequest(Method.GET, "ProposalService/PSACostData/GetPSACostCaseAndFeedData", queryParams);
Console.WriteLine("Base URL - " + restObj.Item2.BaseUrl);
var response = await restObj.Item2.ExecuteTaskAsync(restObj.Item1);
if (response.StatusCode == HttpStatusCode.OK)
{
var result = JsonConvert.DeserializeObject<PSACostCaseDetailsResponse>(response.Content);
Console.WriteLine("result -" + response.Content.ToString());
Console.WriteLine("start writing file");
var excelPackage = await _iPSACostExcelHelper.PopulatePsaCostFile(result, Path.Combine(_hostingEnvironment.ContentRootPath, "App_data", "PSACOST_V9.2.2.xlsm"));
Console.WriteLine("finished writing file");
return await Task.FromResult(File(_excelHelper.ConvertWorkBookToByteArray(excelPackage), ContentTypeEnums.excel, result.customerInformationModel.ProposalNum + "_" + result.caseDataModel.CaseNm + ".xlsm"));
}
throw new Exception("There is no PSA cost data for this case");
}
the line "finished writing file" does get printed to the stdout, the line after that fails. Can someone help me understand what is going wrong here? Why does a return FileResult type method require system.drawing?
Also below is my dockerfile.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2.7-alpine3.10
LABEL pipelineName="PSACOST.API" \
pipelineKey="UMAOKJOH" \
offeringKey="KKWEECBH"
RUN apk upgrade -U
EXPOSE 5000
ENV ASPNETCORE_URLS=http://*:5000
WORKDIR /app
COPY . /app
USER guest
ENTRYPOINT ["dotnet", "PSACOST.API.Web.dll"]