Posting this solution as it may be helpful for those who have upgraded to .NET 8.
I added "FUNCTIONS_INPROC_NET8_ENABLED": 1 in my local settings to avoid the error.
"FUNCTIONS_INPROC_NET8_ENABLED": 1