stride3d/stride · error · InvalidOperationException

Could not resolve generic arguments

Error message

Could not resolve generic arguments

What it means

DispatcherProcessor (IL weaver for generic dispatchers) rebuilds a GenericInstanceType by mapping each generic argument; when the rebuilt argument list has fewer entries than the original generic instance, it throws this InvalidOperationException because the generic type could not be fully closed.

Solutions

  1. Identify the generic type in your code that fails to close and simplify it (use a non-generic or fully closed type)
  2. Ensure all referenced assemblies containing the generic arguments are available and built with a compatible Stride version
  3. Rebuild clean (delete bin/obj) so the processed assembly matches current sources
  4. If a specific API pattern triggers it, avoid that generic pattern or report it as an AssemblyProcessor bug

Example fix

// before
class Dispatcher<T> : IMyDispatcher where T : struct { ... }
// after (close the generic explicitly in usage)
var d = new Dispatcher<MyStruct>(); // fully closed instantiation the processor can resolve
Defensive patterns

Strategy: try-catch

Try / catch

// build-time error; wrap assembly processing in the build task
catch (InvalidOperationException ex) when (ex.Message == "Could not resolve generic arguments")
{
    // identify offending generic type, make instantiation closed
}

Prevention

When it happens

Trigger: AssemblyProcessor scanning an assembly containing a generic instance type whose arguments cannot all be mapped to concrete types in the processing context, during dispatcher method generation.

Common situations: Using generic types/methods over types the processor cannot resolve (e.g. deeply nested or externally defined generics); assemblies compiled with generic patterns the weaver did not anticipate; mixing assemblies compiled against different Stride versions.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/21ad7cbe31bbf73b. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.AssemblyProcessor/DispatcherProcessor.cs:511

        {
            if (genericArgument.IsGenericParameter)
            {
                var genericParameter = GetGenericParameterForArgument(relativeType, genericArgument);
                if (genericParameter != null)
                {
                    genericArguments.Add(genericParameter);
                }
            }
            else
            {
                var newGenericArgument = ChangeGenericArguments(context, genericArgument, relativeType);
                genericArguments.Add(newGenericArgument);
            }
        }

        if (genericArguments.Count != genericInstance.GenericArguments.Count)
        {
            throw new InvalidOperationException("Could not resolve generic arguments");
        }

        return context.Assembly.MainModule.ImportReference(genericInstance.Resolve()).MakeGenericInstanceType(genericArguments.ToArray());
    }

    private MethodReference ChangeGenericArguments(AssemblyProcessorContext context, MethodReference method, TypeReference relativeType)
    {
        if (method is not GenericInstanceMethod genericInstance)
            return method.Resolve().MakeGeneric([.. relativeType.Resolve().GenericParameters]);

        Debugger.Launch();

        var genericArguments = new List<TypeReference>();
        foreach (var genericArgument in genericInstance.GenericArguments)
        {
            if (genericArgument.IsGenericParameter)
            {
                var genericParameter = GetGenericParameterForArgument(relativeType, genericArgument);

View on GitHub (pinned to 96fad776d2)