{"record":{"id":"5294b64872a15c41","repo":"dotnet/machinelearning","slug":"type-ipredictiontransformer-not-implemented-by-pro","errorCode":null,"errorMessage":"Type IPredictionTransformer not implemented by provided type, {type}","messagePattern":"Type IPredictionTransformer not implemented by provided type, (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Transforms/PermutationFeatureImportanceExtensions.cs","lineNumber":734,"sourceCode":"                    name = $\"Slot {i}\";\n                }\n                output.Add(name, permutationFeatureImportance[i]);\n            }\n\n            return output.ToImmutableDictionary();\n        }\n\n        private static Type GetImplementedIPredictionTransformer(Type type)\n        {\n            foreach (Type iType in type.GetInterfaces())\n            {\n                if (iType.IsGenericType && iType.GetGenericTypeDefinition() == typeof(IPredictionTransformer<>))\n                {\n                    return iType;\n                }\n            }\n\n            throw new ArgumentException($\"Type IPredictionTransformer not implemented by provided type, {type}\", nameof(type));\n        }\n\n        #endregion\n    }\n}\n","sourceCodeStart":716,"sourceCodeEnd":740,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Transforms/PermutationFeatureImportanceExtensions.cs#L716-L740","documentation":"GetImplementedIPredictionTransformer reflects over a type looking for an implementation of the generic IPredictionTransformer<> interface; if no closed generic interface is found it throws ArgumentException naming the offending type. PermutationFeatureImportance only knows how to work with prediction transformers, so other transformer kinds are rejected.","triggerScenarios":"Calling PermutationFeatureImportance APIs (e.g., PermutationFeatureImportance<TMetrics> over multiclass/binary/ranking models) with a model/transformer type that does not implement IPredictionTransformer<TData> — e.g., passing a generic ITransformer like a ColumnCopyingTransformer's output or a custom transformer implementation.","commonSituations":"Feeding the output of a non-prediction transform stage into PFI instead of the trained predictor, implementing a custom ITransformer that forgot to implement IPredictionTransformer<TData>, or using a legacy/community transformer built against a different ML.NET interface version.","solutions":["Pass the trained prediction transformer from the model (e.g., the result of `transformer.Model` or the fitted pipeline's final prediction transformer), not an arbitrary ITransformer.","Guard before calling: reflect or check `transformer.GetType().GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPredictionTransformer<>))`.","If it's a custom transformer, implement IPredictionTransformer<TData> on it before using it with PFI.","Wrap the PFI call in try-catch on ArgumentException to report which type was rejected."],"exampleFix":"// before\npfi = mlContext.BinaryClassification.PermutationFeatureImportance(model, data, ...); // model is a raw ITransformer\n\n// after\nvar predModel = ((ISingleFeaturePredictionTransformer<object>)model); // ensure it's a prediction transformer\npfi = mlContext.BinaryClassification.PermutationFeatureImportance(predModel, data, ...);","handlingStrategy":"type-guard","validationCode":"bool IsPredictionTransformer(ITransformer t) =>\n    t.GetType().GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPredictionTransformer<>));","typeGuard":"bool IsPredictionTransformer(ITransformer t) =>\n    t.GetType().GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IPredictionTransformer<>));","tryCatchPattern":"try { var results = mlContext.BinaryClassification.PermutationFeatureImportance(model, data, labelColumnName: \"Label\"); }\ncatch (ArgumentException ex) { log.LogError(ex, \"Transformer does not implement IPredictionTransformer\"); throw new UnsupportedModelException(...); }","preventionTips":["Pass the fitted prediction transformer (from trainer output), not a raw ITransformer.","Implement IPredictionTransformer<TData> on custom transformers before using PFI.","Check model type after `Fit` with a quick interface check in tests."],"tags":["csharp","mlnet","reflection","interface","argument-exception"],"backgroundTag":"incompatible-source-type","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}