Jericho / StrongGrid

Strongly typed library for the entire SendGrid v3 API, including webhooks
183 stars 38 forks source link

.NET 8 support and "Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0" #529

Closed wlewis22 closed 3 months ago

wlewis22 commented 3 months ago

Hi all,

UPDATE: I tried rolling back to v0.108.0, and experienced the same issue. I then tried 0.107.0 of StrongGrid and the issue did not occur. Parsing of the post body worked perfectly. So I am not sure what was introduced in v0.108.0 but it appears to have broken something. END UPDATE.

I have an Azure Functions project targeting .NET 8. The function is a standard HTTP function which will be receiving SendGrid Inbound Parse webhooks.

I am using Version 0.109.0 of Strong Grid.

var parser = new WebhookParser(); var inboundEmail = await parser.ParseInboundEmailWebhookAsync(request.Body);

When I run the above, I get the following error

Executed 'dataServiceInboundEmail' (Failed, Id=439fab89-72dd-4add-b347-6d4bf97d025d, Duration=412ms) [2024-07-26T02:22:15.142Z] System.Private.CoreLib: Exception while executing function: dataServiceInboundEmail. StrongGrid: Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

I am wondering if this is due to a lack of .NET 8 support by StrongGrid, or something else?

If its due to .NET 8 support, is there any ETA on supporting .NET 8 with StrongGrid?

If it is something else, is anyone able to suggest why I might be getting this error and how I can resolve it?

Any help with this would be greatly appreciated. I have tried including System.Net.Http.Formatting, Version=6.0.0.0 in the csproj, but get errors saying that package cannot be found. Not sure where I am going wrong.

Regards,

wlewis22 commented 3 months ago

Update on this issue. Just to be sure, I created a new solution with only a single Azure Functions .NET 8 project.

I sent a standard SendGrid request from Postman to the function and the function picked up the POST request just fine. As soon as it ran:

var inboundEmail = await parser.ParseInboundEmailWebhookAsync(request.Body);

I got the same error.

[2024-07-26T05:39:17.751Z] Executed 'dataServiceInboundEmail' (Failed, Id=0c331241-e613-4e65-9d7d-63efade1c033, Duration=7492ms) [2024-07-26T05:39:17.752Z] System.Private.CoreLib: Exception while executing function: dataServiceInboundEmail. StrongGrid: Could not load file or assembly 'System.Net.Http.Formatting, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

I have seen other issues raised related to other problems by users running on Azure Functions V4 and .NET 8. So I am hoping that it is not a .NET 8 support issue. But if not, then I am quite stuck.

Again, any assistance much appreciated.

Jericho commented 3 months ago

What you are describing is a well-known problem with "in-process" Azure functions. Allow me to emphasize "in-process", this is a rather important detail which is at the heart of this issue. You haven't stated whether you are using in-process or not but I'm going to assume that you are.

I have explained the root of this problem before so I won't explain it again but simply summarize that you can make this problem go away by switching to "out-of-process" (AKA "isolated worker model") Azure functions.

Speaking of in-process vs out-of-process: my understanding is that Microsoft is phasing out "in-process" and is encouraging their customer to switch to out-of-process, as announced here.

Jericho commented 3 months ago

Haven't heard back therefore I will assume my suggestion was helpful

wlewis22 commented 3 months ago

Haven't heard back therefore I will assume my suggestion was helpful

Hi,

Very sorry to not reply. Totally slipped my mind. Your assistance was very much appreciated and certainly helped to explain the issue a lot!

Sure enough it was exactly the cause of the issue and has now been resolved by movie to the isolated worker mode. Many thanks!

Jericho commented 3 months ago

You're welcome. Glad I could help!