c# - 错误 "Class does not contain a definition for method"但方法存在

标签 c# visual-studio

我收到以下错误:

'MyNamespace.MyBaseClass' does not contain a definition for 'MyMethod' and no extension method 'MyMethod' accepting a first argument of type `MyMamespace.MyBaseClass' could be found (are you missing a using directive or an assembly reference?)

当我选择调用方行中的方法并执行 [Go to Definition] 时,Visual Studio 会在预期的位置找到方法声明。

当方法名称更改为MyMethod_ABC 并选择[Generate method stub] 时,方法MyMethod_ABC 会在MyMethod 旁边创建,方法相同签名,只有参数名称不同。

项目无法构建。有人能看出有问题吗?

最佳答案

对于像我一样正在寻找解决方案的任何人:

我刚遇到这个问题,但事实证明,在包含我尝试使用的方法的引用项目中存在一个小的编译错误,并且由于该项目从未使用新方法成功编译过,因此使用它在另一个项目中是无效的。修复了错误,我不再收到此错误。

关于c# - 错误 "Class does not contain a definition for method"但方法存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6821500/

相关文章:

c# - Web 服务引用找不到程序集引用

c++ - 如何强制库使用自定义 std::allocator?

.net - 调试 ASP.NET 应用程序时,如何在 Firefox 关闭时结束调试 session ?

visual-studio - XapCacheFile.xml 错误 - Visual Studio - Windows Phone 7

visual-studio - Frameworks\Microsoft.AspNetCore.App 上的黄色三角形

visual-studio - 使用智能感知和 Vsvim

c# - 我可以在 Azure DevOps 中使用 dotnetpublish 命令发布 .net Framework 4.7.1 解决方案吗

c# - System.net.Sockets.SocketException 无法建立连接,因为目标机器主动拒绝它

c# - 如何合并同一个DataSet中的DataSet表

c# - 在 IIS 中托管 TCP 聊天服务器