{"record":{"id":"7f1173d2f02a7d7c","repo":"dotnet/wpf","slug":"sr-returneventhandlermustbeonparentpage","errorCode":null,"errorMessage":"SR.ReturnEventHandlerMustBeOnParentPage","messagePattern":"SR\\.ReturnEventHandlerMustBeOnParentPage","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ReturnEventSaver.cs","lineNumber":118,"sourceCode":"        internal void _Attach(Object caller, PageFunctionBase child)\n        {\n            ReturnEventSaverInfo[] list = null;\n\n            list = _returnList;\n\n            if (list != null)\n            {\n                Debug.Assert(caller != null, \"Caller should not be null\");\n                for (int i = 0; i < list.Length; i++)\n                {\n                    //\n                    // Future notes: how do we handle listeners that were not on the calling pagefunction ? \n                    // E.g. - if we had a listener to OnFinish from a Button on the calling page.  \n                    //  \"Return event never fired from PageFunction hosted in its own window\"\n                    // \n                    if (!string.Equals(_returnList[i]._targetTypeName, caller.GetType().AssemblyQualifiedName, StringComparison.Ordinal))\n                    {\n                        throw new NotSupportedException(SR.ReturnEventHandlerMustBeOnParentPage);\n                    }\n\n                    Delegate d;\n                    try\n                    {\n                        d = Delegate.CreateDelegate(\n                                                                Type.GetType(_returnList[i]._delegateTypeName),\n                                                                caller,\n                                                                _returnList[i]._delegateMethodName);\n                    }\n                    catch (Exception ex)\n                    {\n                        throw new NotSupportedException(SR.ReturnEventHandlerMustBeOnParentPage, ex);\n                    }\n\n                    child._AddEventHandler(d);\n                }\n            }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ReturnEventSaver.cs#L100-L136","documentation":"ReturnEventSaver._Attach wires a PageFunction's Return event handlers back onto the calling page. It matches each recorded listener by the target page's assembly-qualified type name; if the caller's type differs from the recorded target, the handler is not on the parent page and the library throws NotSupportedException(SR.ReturnEventHandlerMustBeOnParentPage).","triggerScenarios":"Resuming a PageFunction whose Return handler was recorded against a different page type than the object now calling the resume/attach path — e.g. navigation journal restore from a page that isn't the original caller.","commonSituations":"PageFunction hosted in its own window or a different frame; calling page recreated or retyped between calls; custom navigation code invoking the Return flow from a foreign object.","solutions":["Ensure the object resuming the PageFunction is the exact page type that called it (assembly-qualified name must match)","Call the PageFunction from the parent page itself, not a child control or wrapper","Restructure to keep the Return handler on the calling page rather than attaching external listeners"],"exampleFix":"// before\n// Button_Click in some other page calls pageFunction.Start(...) and later resumes it\n// after\n// Start the PageFunction from the parent page method; handle Return on that same page","handlingStrategy":"validation","validationCode":"bool IsCallerParentPage(object caller, string recordedTypeName) => string.Equals(caller.GetType().AssemblyQualifiedName, recordedTypeName, StringComparison.Ordinal);","typeGuard":null,"tryCatchPattern":"try { ResumeFromPageFunction(); } catch (NotSupportedException) { /* caller is not the parent page; route through parent */ }","preventionTips":["Only resume PageFunctions from the exact calling page instance","Do not host the calling PageFunction in a separate window/frame","Keep Return handlers on the parent page, not child controls"],"tags":["wpf","navigation","pagefunction","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}