{"record":{"id":"7076c04669a0b2c0","repo":"egametang/ET","slug":"preservedmethod-method-method-has-generic-para","errorCode":null,"errorMessage":"[PreservedMethod] method:{method} has generic parameters","messagePattern":"\\[PreservedMethod\\] method:(.+?) has generic parameters","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.hybridclr/Scripts/Editor/Share/MethodBridge/Generator.cs","lineNumber":205,"sourceCode":"            if (method.IsPrivate || (method.IsAssembly && !method.IsPublic && !method.IsFamily))\n            {\n                if (klassInst == null && methodInst == null)\n                {\n                    return;\n                }\n                else\n                {\n                    //Debug.Log($\"[PreservedMethod] method:{method}\");\n                }\n            }\n            ICorLibTypes corLibTypes = method.Module.CorLibTypes;\n            TypeSig returnType;\n            List<TypeSig> parameters;\n            if (klassInst == null && methodInst == null)\n            {\n                if (method.HasGenericParameters)\n                {\n                    throw new Exception($\"[PreservedMethod] method:{method} has generic parameters\");\n                }\n                returnType = MetaUtil.ToShareTypeSig(corLibTypes, method.ReturnType);\n                parameters = method.Parameters.Select(p => MetaUtil.ToShareTypeSig(corLibTypes, p.Type)).ToList();\n            }\n            else\n            {\n                var gc = new GenericArgumentContext(klassInst, methodInst);\n                returnType = MetaUtil.ToShareTypeSig(corLibTypes, MetaUtil.Inflate(method.ReturnType, gc));\n                parameters = method.Parameters.Select(p => MetaUtil.ToShareTypeSig(corLibTypes, MetaUtil.Inflate(p.Type, gc))).ToList();\n            }\n\n            var m2nMethod = CreateMethodDesc(method, false, returnType, parameters);\n            AddManaged2NativeMethod(m2nMethod);\n\n            if (method.IsVirtual)\n            {\n                if (method.DeclaringType.IsInterface)\n                {","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.hybridclr/Scripts/Editor/Share/MethodBridge/Generator.cs#L187-L223","documentation":"Thrown by Generator.ProcessMethod when a method has HasGenericParameters == true and there is no class or method instantiation (klassInst == null and methodInst == null). ProcessMethod handles both instantiated and non-instantiated methods; for the non-instantiated path it requires the method to be non-generic, because an open generic method has no concrete signature to bridge.","triggerScenarios":"ProcessMethod(method, klassInst=null, methodInst=null) is reached for a method that is referenced as a preserved/bridge target without a concrete instantiation, and method.HasGenericParameters is true. The code throws before computing returnType/parameters.","commonSituations":"A generic method is referenced (e.g. via MonoPInvokeCallback or a preserved list) without specifying type arguments; the generic reference collector did not record the instantiation; a new generic method was added to a type that participates in reverse P/Invoke.","solutions":["Run HybridCLR/Generate/AOTGenericReference so all generic instantiations are collected and ProcessMethod receives concrete klassInst/methodInst.","If the method should never be bridged generically, remove it from preserved/reverse-P/Invoke targets.","Refactor the method to be non-generic or ensure every call site uses explicit concrete type arguments that the collector can see.","Re-run HybridCLR/Generate/All after collecting instantiations."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// In ProcessMethod: guard the non-instantiated path\nif (klassInst == null && methodInst == null && method.HasGenericParameters)\n    Debug.LogError(\"Method is generic with no instantiation -- cannot bridge.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Collect all generic instantiations via AOTGenericReference before bridge generation.","Do not register open generic methods as reverse-P/Invoke or preserved targets.","Ensure every generic call site uses explicit concrete type arguments visible to the collector."],"tags":["hybridclr","method-bridge","generics","process-method"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}