'Azure Event Grid output binding not working

I have tried every variation of what this document has to offer to make an azure function that takes in an event grid event and outputs and event grid event:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid-output

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;

namespace Azure.Extensions.WebJobs.Sample
{
    public static class CloudEventBindingFunction
    {
        [FunctionName("TestFunctionName")]
        public static async Task RunAsync(
            [EventGridTrigger] EventGridEvent eventGridEvent, [EventGrid(TopicEndpointUri = "TopicEndpointUri", TopicKeySetting = "TopicKeySetting")] IAsyncCollector<EventGridEvent> eventCollector, ILogger log)
        {
            var e = new EventGridEvent("message-id", "subject-name", "event-data", "event-type", DateTime.UtcNow, "1.0");
            await eventCollector.AddAsync(e);
        }
    }
}

Whatever version I use, I get the error in azure saying:

Microsoft.Azure.EventGrid.Models.EventGridEvent is not a valid event type.

I have also tried using the [return: ...] variant of this function, and have the same issue.

My host.json Azure Functions runtime is 2.0

Function runtime version is ~4

Azure function is hosted on App Service Plan (Premium)

The function was initialized with func new dotnet

For the sake of ruling out things, here's my csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>nullable</WarningsAsErrors>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Messaging.EventGrid" Version="4.10.0" />
    <PackageReference Include="Microsoft.Azure.EventGrid" Version="3.2.1" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.2.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source