c# - 在类型上找不到匹配的构造函数。您可以使用 Arguments 或 FactoryMethod 指令来构造类型

标签 c# .net wpf xaml canvas

我希望有人能帮我解决一个奇怪的问题。开发 WPF .NET Framework 4.0 应用程序,接收消息:

No matching constructor found on type. You can use the Arguments or FactoryMethod directives to construct the type when attempting to use the following code.

用户控件:

<Grid>                    
    <GroupBox Header="Diagram">
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <designer:DesignerCanvas Focusable="true" x:Name="MyDesigner"
                Background="{StaticResource WindowBackgroundBrush}" Margin="10"
                FocusVisualStyle="{x:Null}"
                ContextMenu="{StaticResource DesignerCanvasContextMenu}" />
        </ScrollViewer>
    </GroupBox>
</Grid>

类:

/// <summary>
/// The designer canvas.
/// </summary>
public partial class DesignerCanvas : Canvas
{
    public DesignerCanvas()
    {
      ....
    }
}

据我所知,代码似乎没有任何问题。

谢谢, 约翰

更新:

事实证明这是在掩盖底层异常。我在 DesignerCanvas 的构造函数中去掉了任何东西,它起作用了。然后我在一个单独的方法中重新添加设置命令绑定(bind)并收到:

System.MissingMethodException: Method not found: Void System.Windows.Input.CommandBinding..ctor(System.Windows.Input.ICommand, System.Windows.Input.ExecutedRoutedEventHandler)

构造函数包括尝试设置一些命令绑定(bind)。例如

public void SetupCommandDefaults()
    {
        this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, this.New_Executed));
    }

我正在卸载并重新安装 .NET Framework 4.0,希望这能解决问题。

最佳答案

事实证明,在重新安装 .NET Framework 4、应用各种 KB 补丁直至并包括运行时 4.0.3 之后经历了很多痛苦。问题是由 ILMerge msbuild 步骤引起的。

构建过程包括构建后的 msbuild 任务,用于将主要可执行文件与一些 dll 合并。

我删除了这个 ILMerge 步骤,错误消失了。

不确定为什么会发生在这个环境中,而不是在我们的任何测试机器上,但它现在可以正常工作了。

关于c# - 在类型上找不到匹配的构造函数。您可以使用 Arguments 或 FactoryMethod 指令来构造类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17651310/

相关文章:

c# - 以并行和顺序方式执行 N 个线程

C#从gridview asp net的下拉列表中获取选定的值

c# - .NET 版本的 HTML Tidy?

.net - 如何在不使用2068的情况下在.NET中获取MQSeries队列名称

c# - 如何在 datagrid C# wpf 中动态行?

c# - 是否可以将参数(绑定(bind))传递给 WPF 样式

c# - 查找未处置的 IDisposables

c# - 使用 DirectoryServices.AccountManagement 从 OU 获取组

.net - Double.ToString ("C")返回不正确的货币符号

c# - 在列表框 WPF 中绑定(bind)组合框