wpf “该类型不包括任何可访问的构造函数” - 具有无参数构造函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36981415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:47:01  来源:igfitidea点击:

"The type does not include any accessible constructors" - has parameterless constructor

c#wpf

提问by Joe

I'm trying to load a class as a static resource:

我正在尝试将类加载为静态资源:

<UserControl.Resources>
    <myControls:HelpTip x:Key="NavagationHT" Message="Test help tip message for navagation" />
</UserControl.Resources>

And I'm getting the error "The type HelpTip does not include any accessible constructors". However, the class is public, and has a parameterless constructor that should be accessible:

我收到错误“HelpTip 类型不包含任何可访问的构造函数”。但是,该类是公共的,并且具有应该可以访问的无参数构造函数:

public class HelpTip : PropertyChangedBase
{
    ...

    public HelpTip()
    {
        ID = Guid.NewGuid();
        HelpTipManager.AddHelpTip(this);
    }
}

Does anyone know of anything else that could be causing this error?

有没有人知道可能导致此错误的其他任何事情?

Edit:It's resolved now. I'm not sure how or why, maybe there were some problems elsewhere that was causing the code to be looking up an old version where there was no parameterless constructor?

编辑:现在已经解决了。我不确定如何或为什么,也许其他地方存在一些问题导致代码查找没有无参数构造函数的旧版本?

回答by Mike Loux

As mentioned in my comment on the question, I run into this, as well, on a regular basis. I am using Visual Studio 2015, Update 3.

正如我在对该问题的评论中所提到的,我也经常遇到这种情况。我正在使用 Visual Studio 2015 更新 3。

I just resolved this (for now) by closing the solution, and Visual Studio, then removing the bin and obj folders from the project my XAML file was in, then re-opening VS, the solution and doing a Clean All and Rebuild All (something I generally do anyway, as I've been burned by stale project builds in the past.

我只是通过关闭解决方案和 Visual Studio 解决了这个问题(目前),然后从我的 XAML 文件所在的项目中删除 bin 和 obj 文件夹,然后重新打开 VS,解决方案并执行 Clean All 和 Rebuild All(无论如何,我通常会做一些事情,因为过去我已经被陈旧的项目构建所困扰。

Not a greatanswer, per se, but it allowed me to continue working, so at least it's a viable workaround. Hopefully it'll work for other people as well.

本身不是一个很好的答案,但它让我可以继续工作,所以至少这是一个可行的解决方法。希望它也适用于其他人。

回答by Max Zaikin

Restart VS works for me, without cleaning. rebuilding and bin removing.

重新启动 VS 对我有用,无需清理。重建和垃圾箱删除。

I'm using VS v. 15.5.7

我正在使用 VS v. 15.5.7