系统.MissingMethodException: Method not found: '字符串.get_Da

本文关键字:字符串 get Da MissingMethodException Method not found 系统 | 更新日期: 2023-09-27 18:14:31

我有以下类型:

public class TimeBand
{
    public string DayName { get; set; }
    public int customerId { get; set; }
}

和我正在创建一个包含TimeBands的列表:

var TimeBandList = new List<TimeBand>
    {
        new TimeBand()
            {
                DayName = DayOfWeek.Monday.ToString(),
                customerId = 10
            },
        new TimeBand()
            {
                DayName = DayOfWeek.Tuesday.ToString(),
                customerId = 11
            }
            .....
    };

我正在使用以下内容将TimeBands加载到另一个List中:

    var timeBandRange = new List<TimeBand>();
    timeBandRange = TimeBandList.Where
                  (p => p.customerId == newCustomerId  
                     && p.DayName == date.DayOfWeek.ToString()).ToList();

这是工作良好,但在TimeBand类我决定改变类型的DayName属性为DayOfWeekstring所以代码变成这样:

public class TimeBand
{
    public DayOfWeek DayName { get; set; }
    public int customerId { get; set; }
}
var TimeBandList = new List<TimeBand>
    {
        new TimeBand()
            {
                DayName = DayOfWeek.Monday,
                customerId = 10
            },
        new TimeBand()
            {
                DayName = DayOfWeek.Tuesday,
                customerId = 11
            }
            .....
    };
    DateTime date = IndDate;
    var timeBandRange = new List<TimeBand>();
    timeBandRange = TimeBandList.Where
                  (p => p.customerId == parameter.customerId  
                     && p.DayName == date.DayOfWeek).ToList();

这个新代码现在在TimeBandList上失败了。其中行,并给出以下错误:MissingMethodException: Method not found: 'System. '字符串TimeBand.get_DayName()"。

知道为什么吗?

谢谢

系统.MissingMethodException: Method not found: '字符串.get_Da

也许你只需要重新编译?我在本地运行这段代码,它工作得很好。

class Program
{
    static void Main(string[] args)
    {
        TimeBand.DoSomething();
    }
}

public class TimeBand
{
    public DayOfWeek DayName { get; set; }
    public int customerId { get; set; }
    public static void DoSomething()
    {
        var TimeBandList = new List<TimeBand>
            {
                new TimeBand()
                    {
                        DayName = DayOfWeek.Monday,
                        customerId = 10
                    },
                new TimeBand()
                    {
                        DayName = DayOfWeek.Tuesday,
                        customerId = 11
                    }
            };

            DateTime date = DateTime.Now;
            var timeBandRange = new List<TimeBand>();
            timeBandRange = TimeBandList.Where
                          (p => p.customerId == 1  
                             && p.DayName == date.DayOfWeek).ToList();
                }
            }

我以前也遇到过同样的问题。我有一个SharePoint项目,它引用了一个类库。在。net 4.0及以上版本中,dll被插入到这个位置:C:'Windows'Microsoft.NET'assembly'GAC_MSIL'。因此,如果您得到与上面相同的错误,那么您需要重新构建解决方案并再次在GAC_MSIL中部署DLL,否则它仍然会引用旧的DLL。

在我的情况下,问题是,我已经将库中的属性类型从string更改为int。在另一个项目中,属性变量赋值给动态变量在编译时它不会给出任何错误,但在运行时它会抛出这个错误。为了解决这个问题,我需要编译具有动态变量分配的项目,它没有任何变化。现在它运行良好。