PrismLibrary/Prism · error · DialogException
UnableToSetTheDialogCloseListener
UnableToSetTheDialogCloseListener
Error message
DialogException.UnableToSetTheDialogCloseListener
What it means
DialogUtilities.GetListenerSetter walks the dialog's type hierarchy to find the private DialogCloseListener field; if it reaches a base type of null or object without finding the field, it throws DialogException with code UnableToSetTheDialogCloseListener. This means the class is not a Prism dialog (DialogViewModelBase-derived) and cannot receive the close callback.
Solutions
- Make the dialog's binding context derive from DialogViewModelBase (or DialogBase)
- Register the dialog with the correct view/view-model pair so DialogService receives the right instance
- Verify the class hierarchy retains Prism's dialog base class
- Catch DialogException in dialog registration/show code and validate the type beforehand
Example fix
// before
public class MyDialogViewModel { } // not a Prism dialog VM
// after
public class MyDialogViewModel : DialogViewModelBase { } Defensive patterns
Strategy: type-guard
Validate before calling
if (dialogAware is not DialogViewModelBase && dialogAware is not DialogBase)
throw new ArgumentException("Object is not a Prism dialog", nameof(dialogAware)); Type guard
bool isPrismDialog(IDialogAware d) =>
d.GetType().BaseType != null && typeof(DialogViewModelBase).IsAssignableFrom(d.GetType()); Try / catch
try { await dialogService.ShowDialogAsync(name, parameters, cb); }
catch (DialogException ex) when (ex.Code == DialogExceptionCode.UnableToSetTheDialogCloseListener)
{ logger.LogError(ex, "'{Name}' is not a Prism dialog", name); } Prevention
- Derive all dialog view-models from DialogViewModelBase
- Verify dialog registration pairs view and view-model correctly
- Do not remove Prism's private close-listener field via custom base classes
- Add a startup assertion that each registered dialog inherits the Prism base class
When it happens
Trigger: Passing an object to DialogService that does not derive from DialogViewModelBase/DialogBase (no _closeListener field anywhere in its hierarchy), e.g. a plain view or wrong view-model registered as a dialog.
Common situations: Registering a dialog whose view-model does not inherit Prism's DialogViewModelBase; renaming or removing the listener field via custom base classes; upgrading Prism where the field location changed.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Prism applications only support the use of PrismWindow, but…
- The object must be of type
- The view must inherit from VisualElement.
- Could not find Invoke() method for delegate of type
- Unable to convert the value of Type
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/46d4dc6abbbea83d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Prism.Core/Dialogs/DialogUtilities.cs:68
{
return x => propInfo.SetValue(dialogAware, x);
}
var fields = type.GetRuntimeFields().Where(x => x.FieldType == typeof(DialogCloseListener));
var field = fields.FirstOrDefault(x => x.Name == $"<{nameof(IDialogAware.RequestClose)}>k__BackingField");
if (field is not null)
{
return x => field.SetValue(dialogAware, x);
}
else if (fields.Any())
{
field = fields.First();
return x => field.SetValue(dialogAware, x);
}
var baseType = type.BaseType;
if (baseType is null || baseType == typeof(object))
throw new DialogException(DialogException.UnableToSetTheDialogCloseListener);
return GetListenerSetter(dialogAware, baseType);
}
}
View on GitHub (pinned to 358118cd64)