我希望有人能帮我解决一个奇怪的问题。开发 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/