Azure / azure-functions-vs-build-sdk

MSBuild task for Azure Functions
MIT License
96 stars 62 forks source link

AF V4 / Net 6.0 / Linux Plan/ GenerateRuntimeConfigurationFiles / runtimeconfig.template.json not used #553

Closed laurentAstonIf closed 1 year ago

laurentAstonIf commented 2 years ago

Hi

  1. I'm migrating from AF V3/ Core 3.1 to AF V4 / Net 6.0

(hosted on Function App with linux plan)

Some of my functions use external components that still use System.Drawing.Common which make these functions crash with "System.Drawing.Common: The type initializer for 'Gdip' threw an exception. System.Drawing.Common: System.Drawing.Common is not supported on non-Windows platforms"

I have added in my function project file <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> and within the main directory runtimeconfig.template.json with content { "configProperties": { "System.Drawing.EnableUnixSupport": true } }

this is the content of MyFunction.runtimeconfig.json which is generated { "runtimeOptions": { "tfm": "net6.0", "framework": { "name": "Microsoft.NETCore.App", "version": "6.0.0" }, "configProperties": { "System.Drawing.EnableUnixSupport": true } } }

Running the function still produce :not supported on non-Windows platforms

  1. if i set the property GenerateRuntimeConfigurationFiles to false i have warnings at build time warning CA1416: This call site is reachable on all platforms. 'Image.Width' is only supported on: 'windows' => i can understand that it will crash

but if the param is set to true, then i have no warning which make me thought that the parameter + runtimeconfig.template.json was understood/manage

  1. The same process has been applied to an asp net.core webapp hosted on the same plan and it works

Am I missing something or it's a bug ?

i have created a simple function under wsl2 with func new --template "Http Trigger" --name MyDrawingHttpTrigger and add a call to Bitmap => this project is included in the sample.zip

Regards Laurent dotnet --version : 6.0.300 Microsoft.NET.Sdk.Functions : 4.1.0 sample.zip

laurentAstonIf commented 2 years ago

Hi i have actually solved this problem using AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true); in the startup of the azure function

Ved2806 commented 2 years ago

Hi @pragnagopa could you please look into this issue?

Ved2806 commented 1 year ago

Hi @laurentAstonIf Can we close it as resolved? or you still need anything from us?

laurentAstonIf commented 1 year ago

My workaround is working so you can close it Thanks

Ved2806 commented 1 year ago

@laurentAstonIf Thanks.