stride3d/stride · error · ArgumentException
The parameter of this converter must be an instance of the
Error message
The parameter of this converter must be an instance of the {nameof(XamlMarkdown)} class. What it means
TextToMarkdownFlowDocumentConverter optionally accepts an XamlMarkdown engine as its converter parameter to control Markdown rendering. It throws this ArgumentException from Convert (TextToMarkdownFlowDocumentConverter.cs:18) only when parameter is non-null AND not an XamlMarkdown instance, because it later casts parameter to XamlMarkdown.
Solutions
- Remove the ConverterParameter entirely so the default XamlMarkdown engine is used (parameter == null is allowed).
- Pass an actual `new XamlMarkdown()` (or a XamlMarkdown resource) as the parameter.
- Configure a shared XamlMarkdown as a StaticResource and reference it via ConverterParameter="{StaticResource md}".
- Guard with `parameter is XamlMarkdown or null` before calling Convert.
Example fix
// before
<TextBlock ... ConverterParameter="github" /> <!-- string, throws -->
// after
<md:XamlMarkdown x:Key="Engine"/>
<TextBlock ... ConverterParameter="{StaticResource Engine}" /> Defensive patterns
Strategy: validation
Validate before calling
bool ok = parameter == null || parameter is XamlMarkdown;
Type guard
static bool HasValidEngine(object p) => p is null or XamlMarkdown;
Try / catch
try { return converter.Convert(value, targetType, param, culture); }
catch (ArgumentException) { return null; } Prevention
- Omit ConverterParameter to use the built-in default XamlMarkdown engine.
- Share a configured XamlMarkdown via StaticResource if custom rendering is needed.
- Don't pass flags/strings as parameters to this converter — configuration goes on the XamlMarkdown instance.
When it happens
Trigger: Passing a non-XamlMarkdown, non-null ConverterParameter — e.g. a string, a boolean flag, or another IMarkdown engine implementation — into a binding using this converter.
Common situations: Developers passing configuration strings or flags via ConverterParameter out of habit; supplying a different Markdown engine type after a library refactor; copy-paste from converters that take string parameters.
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
- is not a numeric type
- The object passed to this value converter is not a type.
- The parameter of the ConvertBack method of this converter…
- The parameter of the ConvertBack method of this converter…
- The parameter of the ConvertBack method of this converter…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/9b84d4c96b5d7099.
Report an issue: GitHub.
Appendix: source
Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/TextToMarkdownFlowDocumentConverter.cs:18
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Documents;
namespace Stride.Core.Presentation.ValueConverters
{
[ValueConversion(typeof(string), typeof(FlowDocument))]
public class TextToMarkdownFlowDocumentConverter : OneWayValueConverter<TextToMarkdownFlowDocumentConverter>
{
/// <inheritdoc/>
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter != null && !(parameter is XamlMarkdown))
{
throw new ArgumentException($"The parameter of this converter must be an instance of the {nameof(XamlMarkdown)} class.");
}
if (value == null)
return null;
var engine = (XamlMarkdown)parameter ?? defaultMarkdown.Value;
if (engine == null)
return null;
try
{
var text = value.ToString();
return engine.Transform(text);
}
catch (ArgumentException) { }
catch (FormatException) { }
catch (InvalidOperationException) { }
View on GitHub (pinned to 96fad776d2)