{"record":{"id":"6b5617bd30b249b6","repo":"dotnet/machinelearning","slug":"did-not-find-access-modifier-parameter-methodinf","errorCode":null,"errorMessage":"Did not find access modifier (Parameter 'methodInfo')","messagePattern":"Did not find access modifier \\(Parameter 'methodInfo'\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs","lineNumber":33,"sourceCode":"\n\ninternal static class Extension\n{\n    internal static AccessModifier Accessmodifier(this MethodInfo methodInfo)\n    {\n        if (methodInfo.IsFamilyAndAssembly)\n            return AccessModifier.PrivateProtected;\n        if (methodInfo.IsPrivate)\n            return AccessModifier.Private;\n        if (methodInfo.IsFamily)\n            return AccessModifier.Protected;\n        if (methodInfo.IsFamilyOrAssembly)\n            return AccessModifier.ProtectedInternal;\n        if (methodInfo.IsAssembly)\n            return AccessModifier.Internal;\n        if (methodInfo.IsPublic)\n            return AccessModifier.Public;\n        throw new ArgumentException(\"Did not find access modifier\", nameof(methodInfo));\n    }\n\n    internal static AccessModifier Accessmodifier(this ConstructorInfo constructorInfo)\n    {\n        if (constructorInfo.IsFamilyAndAssembly)\n            return AccessModifier.PrivateProtected;\n        if (constructorInfo.IsPrivate)\n            return AccessModifier.Private;\n        if (constructorInfo.IsFamily)\n            return AccessModifier.Protected;\n        if (constructorInfo.IsFamilyOrAssembly)\n            return AccessModifier.ProtectedInternal;\n        if (constructorInfo.IsAssembly)\n            return AccessModifier.Internal;\n        if (constructorInfo.IsPublic)\n            return AccessModifier.Public;\n        throw new ArgumentException(\"Did not find access modifier\", nameof(constructorInfo));\n    }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Core/ComponentModel/ComponentCatalog.cs#L15-L51","documentation":"The Accessmodifier extension on MethodInfo maps reflection's visibility flags to the internal AccessModifier enum. If none of the tested flags (IsFamilyAndAssembly/IsFamily/IsPrivate/IsFamilyOrAssembly/IsAssembly/IsPublic) is true, the method's visibility cannot be classified and this ArgumentException is thrown with param name 'methodInfo'.","triggerScenarios":"ComponentCatalog scans candidate methods and calls Accessmodifier(methodInfo) on a MethodInfo whose visibility flags match none of the expected combinations — essentially unreachable with a healthy reflection surface, but triggered by exotic/proxy/dynamic-method types or a method added by a compiler emitting non-standard visibility.","commonSituations":"Registering components in a ComponentCatalog from dynamically generated assemblies (Reflection.Emit, proxies) whose methods have unusual visibility; corrupted/duplicated assemblies loaded into the AppDomain.","solutions":["Inspect the MethodInfo's attributes (IsPublic, IsPrivate, etc.) before registering the component to confirm it has standard CLR visibility.","Register components from the normal statically compiled assembly instead of dynamic/proxy assemblies.","Catch ArgumentException around component registration and skip unclassifiable members.","If reproducible with a specific assembly, decompile it and check the method's access flags; recompile the component."],"exampleFix":"// before\ncatalog.RegisterComponent(typeof(MyComponent)); // blindly scans all methods\n// after\nvar ok = typeof(MyComponent).GetMethods().All(m =>\n    m.IsPublic || m.IsPrivate || m.IsFamily || m.IsAssembly ||\n    m.IsFamilyOrAssembly || m.IsFamilyAndAssembly);\nif (ok) catalog.RegisterComponent(typeof(MyComponent));","handlingStrategy":"validation","validationCode":"var m = typeof(MyComponent).GetMethod(\"Train\");\nbool classifiable = m.IsPublic || m.IsPrivate || m.IsFamily ||\n    m.IsAssembly || m.IsFamilyOrAssembly || m.IsFamilyAndAssembly;\nif (classifiable) catalog.RegisterComponent(typeof(MyComponent));","typeGuard":"static bool HasStandardVisibility(MethodInfo m) =>\n    m.IsPublic || m.IsPrivate || m.IsFamily ||\n    m.IsAssembly || m.IsFamilyOrAssembly || m.IsFamilyAndAssembly;","tryCatchPattern":"try\n{\n    catalog.RegisterComponent(candidateType);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"methodInfo\")\n{\n    logger.LogWarning($\"Skipped {candidateType}: non-standard method visibility\");\n}","preventionTips":["Register only statically compiled types, not Reflection.Emit proxies.","Avoid loading duplicate component assemblies into the process.","Pre-screen candidate types with reflection before registration.","Keep component assemblies built with a standard compiler (csc/Roslyn)."],"tags":["reflection","mlnet","component-catalog","invariant"],"backgroundTag":"internal-invariant-violation","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"}