{"record":{"id":"9b7dcebd9d58a96f","repo":"dotnet/runtime","slug":"part-not-found-while-looking-up-function-name","errorCode":null,"errorMessage":"${part} not found while looking up ${function_name}","messagePattern":"(.+?) not found while looking up (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/invoke-js.ts","lineNumber":404,"sourceCode":"        scope = importedModules.get(js_module_name);\n        if (WasmEnableThreads) {\n            mono_assert(scope, () => `ES6 module ${js_module_name} was not imported yet, please call JSHost.ImportAsync() on the UI or JSWebWorker thread first in order to invoke ${function_name}.`);\n        } else {\n            mono_assert(scope, () => `ES6 module ${js_module_name} was not imported yet, please call JSHost.ImportAsync() first in order to invoke ${function_name}.`);\n        }\n    } else if (parts[0] === \"INTERNAL\") {\n        scope = INTERNAL;\n        parts.shift();\n    } else if (parts[0] === \"globalThis\") {\n        scope = globalThis;\n        parts.shift();\n    }\n\n    for (let i = 0; i < parts.length - 1; i++) {\n        const part = parts[i];\n        const newscope = scope[part];\n        if (!newscope) {\n            throw new Error(`${part} not found while looking up ${function_name}`);\n        }\n        scope = newscope;\n    }\n\n    const fname = parts[parts.length - 1];\n    const fn = scope[fname];\n\n    if (typeof (fn) !== \"function\") {\n        throw new Error(`${function_name} must be a Function but was ${typeof fn}`);\n    }\n\n    // if the function was already bound to some object it would stay bound to original object. That's good.\n    return fn.bind(scope);\n}\n\nexport function set_property (self: any, name: string, value: any): void {\n    mono_check(self, \"Null reference\");\n    self[name] = value;","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/invoke-js.ts#L386-L422","documentation":"Thrown by mono_wasm_lookup_js_import in invoke-js.ts while walking the dotted path of a [JSImport] function name (e.g. MyNs.SubNs.method). It iterates all parts except the last, descending the scope chain; if any intermediate property is missing it throws with the offending part and the full function name. This means the JS object graph does not match the managed import attribute.","triggerScenarios":"A [JSImport(\"A.B.foo\")] where A exists but A.B is undefined; importing from a module object that has not been fully populated; a typo in the dotted path; the JSExport/globalThis target object was reshaped.","commonSituations":"Renaming a JS namespace without updating the [JSImport] attribute; importing before the JS module that defines the namespace has loaded (with threads, before JSHost.ImportAsync on the UI/worker thread).","solutions":["Verify the dotted path in [DllImport]/[JSImport] matches the actual JS object graph (log the scope at each step).","Ensure the containing JS module was imported via JSHost.ImportAsync before the JSImport is invoked (threads).","Fix typos in the namespace segments."],"exampleFix":"// before: [JSImport(\"MyApp.Utilz.parse\")] but Utilz is named Utils\n// after:\n[JSImport(\"MyApp.Utils.parse\")] static partial int Parse();","handlingStrategy":"validation","validationCode":"// validate the dotted path resolves before the JSImport is bound\nfunction resolvePath(root: any, dotted: string): boolean {\n  let scope = root;\n  for (const part of dotted.split('.').slice(0, -1)) {\n    if (scope == null || !(part in scope)) return false;\n    scope = scope[part];\n  }\n  return scope != null;\n}","typeGuard":"function isResolvableNamespace(root: any, dotted: string): boolean {\n  let scope = root;\n  for (const part of dotted.split('.')) {\n    if (scope == null || typeof scope !== 'object') return false;\n    scope = scope[part];\n  }\n  return true;\n}","tryCatchPattern":null,"preventionTips":["Keep [JSImport] paths in sync with the JS module's export shape.","When using threads, call JSHost.ImportAsync on the UI/worker thread before invoking.","Unit-test namespace resolution against the real JS module."],"tags":["jsimport","interop","namespace","binding"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}