'Unhandled TypeLoadException caused by the generic type 'ByRefFunc`2'

I was working on a web app project using asp net core 5.0 and razor pages and it was going smoothly until it started giving me this error when i wanted to redirect to another page:

An unhandled exception occurred while processing the request.
TypeLoadException: The generic type 'ByRefFunc`2' was used with an invalid instantiation in assembly 'Microsoft.AspNetCore.Mvc.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
•   TypeLoadException: The generic type 'ByRefFunc`2' was used with an invalid instantiation in assembly 'Microsoft.AspNetCore.Mvc.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
o   System.RuntimeTypeHandle.Instantiate(QCallTypeHandle handle, IntPtr* pInst, int numGenericArgs, ObjectHandleOnStack type)
o   System.RuntimeTypeHandle.Instantiate(Type[] inst)
o   System.RuntimeType.MakeGenericType(Type[] instantiation)
o   Microsoft.Extensions.Internal.PropertyHelper.MakeFastPropertyGetter(Type openGenericDelegateType, MethodInfo propertyGetMethod, MethodInfo openGenericWrapperMethod)
o   Microsoft.Extensions.Internal.PropertyHelper.MakeFastPropertyGetter(PropertyInfo propertyInfo, MethodInfo propertyGetterWrapperMethod, MethodInfo propertyGetterByRefWrapperMethod)
o   Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreateSinglePropertyDetails(ModelMetadataIdentity propertyKey, PropertyHelper propertyHelper)
o   Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.CreatePropertyDetails(ModelMetadataIdentity key)
o   Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider.GetMetadataForProperties(Type modelType)
o   Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata.get_Properties()
o   Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexObjectModelBinderProvider.GetBinder(ModelBinderProviderContext context)
o   Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinderCoreUncached(DefaultModelBinderProviderContext providerContext, object token)
o   Microsoft.AspNetCore.Mvc.ModelBinding.ModelBinderFactory.CreateBinder(ModelBinderFactoryContext context)
o   Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageBinderFactory.CreateHandlerBinder(ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, IModelBinderFactory modelBinderFactory, CompiledPageActionDescriptor actionDescriptor, HandlerMethodDescriptor handler, MvcOptions mvcOptions)
o   Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.GetHandlerBinders(CompiledPageActionDescriptor actionDescriptor)
o   Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.CreateCacheEntry(ActionInvokerProviderContext context, FilterItem[] cachedFilters)
o   Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvokerProvider.OnProvidersExecuting(ActionInvokerProviderContext context)
o   Microsoft.AspNetCore.Mvc.Infrastructure.ActionInvokerFactory.CreateInvoker(ActionContext actionContext)
o   Microsoft.AspNetCore.Mvc.Routing.ActionEndpointFactory+<>c__DisplayClass7_0.<CreateRequestDelegate>b__0(HttpContext context)
o   Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
o   Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
o   Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
o   Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
o   Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

From what i can see it's an instantiation problem in the Microsoft.AspNetCore.Mvc.Core dll but i don't know what to do can somebody help me?

The redirect code on the Index.cshtml.cs:

public ActionResult OnPostRedirect(string ipAdd)
        {
            //deviceIp = ipAdd;
            return Redirect($"/InterfaceTraffic/{ipAdd}");
        }

The top part of the page InterfaceTraffic.cshtml:

@page "/InterfaceTraffic/{ip}"
@model WebSniffer.Pages.InterfaceTrafficModel
@{
    ViewData["Title"] = "Selected Interfaces Traffic";
}

And the on get function in InterfaceTraffic.cshtml.cs:

public void OnGet()
        {
            capture = false;            
            device = CaptureDeviceList.Instance.FirstOrDefault(x => parseDevice(x)[1] == ip);
            if (device == null)
                Redirect("/");
            devicePorp = parseDevice(device);
            device.OnPacketArrival +=
                new PacketArrivalEventHandler(OnPacketArrival);            
        }


Sources

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

Source: Stack Overflow

Solution Source