自定义 WPF TextBlock 呈现器 - 错误 CS0433

Custom WPF TextBlock Renderer - Error CS0433

我想为项目创建自定义 TextRenderer。当我尝试使用 MarkedNet.Marked class 时,我不断收到 CS0433 错误。我从微软如何在那里做 Wpf TextRenderer 开始,但不知道如何阻止错误发生。

private static TextBlock CreateControl(ScreenTextElement textElement, AdaptiveRenderContext context)
{
            Marked marked = new Marked();
            
            marked.Options.Renderer = new AdaptiveXamlMarkdownRenderer();
            marked.Options.Mangle = false;
            marked.Options.Sanitize = true;

            string text = RendererUtilities.ApplyTextFunctions(textElement.Text, context.Lang); 
            string xaml = $"<TextBlock  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">{marked.Parse(text)}</TextBlock>
}";

Error CS0433 The type 'Marked' exists in both 'AdaptiveCards, Version=2.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.MarkedNet, Version=1.0.13.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

感谢您的帮助。

显示该消息是因为 Microsoft.MarkedNet 和 AdaptiveCards 包含相同的类型,具有完全相同的命名空间和类型名称。 您可以在项目设置中为 AdaptiveCards 或 Microsoft.MarkedNet 指定别名,如下所示 (*)

然后通过定义 using

使用带别名前缀的完全限定名称
using Marked = myAlias::Microsoft.MarkedNet.Marked;

或直接使用完全限定的类型名称

myAlias::Microsoft.MarkedNet.Marked marked = new myAlias::Microsoft.MarkedNet.Marked();

(*) 如果程序集被直接引用,请改为单击程序集引用