简体   繁体   English

C#:找不到方法异常(Setter缺失)

[英]C#: Method not found exception (Setter missing)

I'm facing really strange error while debugging my program. 调试我的程序时,我遇到了非常奇怪的错误。 I have a data contract where I added new properties but one of them cause the following exception: 我有一个数据合同,我添加了新属性,但其中一个导致以下异常:

Method not found: 'Void Measurement.set_ContactId(Int32)'.

The data contract looks following: 数据合同如下:

[DataContract]
public class Measurement
{
    [DataMember]
    public int FactId { get; set; }

    [DataMember]
    public int ContactId { get; set; }
.....

I don't really understand what can be a problem since, as I said, I added some other properties but there was no problem with them. 我真的不明白什么是问题,因为正如我所说,我添加了一些其他属性,但它们没有问题。

UPD: The exception is happening on the service side when I try to assign a value to ContactId : UPD:当我尝试为ContactId分配值时,服务端发生异常:

foreach (Measurement m in result.Where(m => m.FactId == factId)){
    m.ContactId = contactId;
  .....

The problem was with some older version of the DLL which was stored in .NET's cache. 问题在于一些旧版本的DLL存储在.NET的缓存中。 I made a search on the whole disk for the DLL and deleted all found files (some were in use by the .NET so I had to use Unlocker). 我在整个磁盘上搜索了DLL并删除了所有找到的文件(有些是.NET使用的,所以我不得不使用Unlocker)。 After rebuilding the project it worked fine. 重建项目后,它工作正常。

If this Measurement class is part of your WCF service, then you have it on both side of your service (client side and server side). 如果此Measurement类是WCF服务的一部分,那么您可以在服务的两端(客户端和服务器端)使用它。 Do both side have the same version (where ContactId has a setter)? 双方是否都有相同的版本(ContactId有一个setter)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM