找不到方法的私有访问器 [英] Private Accessor for method is not found

查看:21
本文介绍了找不到方法的私有访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2010 下使用上下文菜单生成新单元测试时出现此错误(右键单击方法名称 ->生成单元测试"):

I'm getting this error when generating a new unit test under Visual Studio 2010 using the context menu (right-click the method name -> "Generate Unit Tests"):

Private Accessor for methodName is not found. Please rebuild the containing project or run the Publicize.exe manually.

该方法是公共的(通过应用过滤器在生成单元测试"对话框中不显示非公共方法来检查.

The method is public (checked that by applying applying a filter to not show non-public methods in the "Generate Unit Tests" dialog.

Visual Studio 会自动创建某种 .accessor 文件.我需要在里面做些什么吗?

Visual Studio creates some kind of .accessor file automatically. Do I need to do anything in it?

还有什么问题?

编辑(更多可能相关的信息)

EDIT (more info that might be relevant)

  • 我正在尝试测试网站项目中的一些类,尽管它们不做任何与网页相关的事情.它们只是普通的旧 C# 类.
  • 我所有的类名都可以在单元测试类中作为 ClassName_Accessor 使用.这会导致编译器抱怨方法签名不正确.

推荐答案

我解决了这个问题,我在与 TFS 的拙劣合并期间取消了 Test Reference 文件夹的关联.

I resolved my problem with this, I had disassociated the Test Reference folder during a botched merge with TFS.

Test Reference 文件夹位于您的测试项目中,它将包含一个以源命名空间命名的文件,并附加了.accessor".由于我已将文件夹与我的项目分离,我没有看到该文件仍在那里,所以我突出显示了测试项目并按下了解决方案资源管理器中的显示所有文件"按钮.当我最终找到该文件时,我将其删除并重新生成了私有访问器(在您的类中右键单击并选择生成私有访问器").

The Test Reference folder lives in your test project and will contain a file named after the source namespace with ".accessor" appended to it. Since I had dissociated the folder from my project I didn't see that the file was still there, so I highlighted the test project and pressed the "Show All Files" button in Solution Explorer. When I finally found the file, I deleted it and re-generated the private accessor (right click in your class and choose "Generate Private Accessor").

所以最重要的是,如果测试引用存在但与项目解除关联,您将无法重新生成私有访问器,并且 Visual Studio 不会告诉您存在文件命名/锁定冲突.

So bottom line, if Test Reference exists but is disassociated from the Project you won't be able to regenerate the private accessor and Visual Studio will not tell you that there is a file naming/locking conflict.

这篇关于找不到方法的私有访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆