Question

I have the following type:

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

and I am creating a list which contains TimeBands:

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

And I am using the following to load TimeBands into another List:

    var timeBandRange = new List<TimeBand>();

    timeBandRange = TimeBandList.Where
                  (p => p.customerId == newCustomerId  
                     && p.DayName == date.DayOfWeek.ToString()).ToList();

This was working fine but in the TimeBand class I decided to change the type of the DayName property to DayOfWeek from string so the code has become like this:

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();

This new code is now failing on the TimeBandList.Where line and giving the following error: System.MissingMethodException: Method not found: 'System.String TimeBand.get_DayName()'.

Any idea why?

Thanks

Was it helpful?

Solution

Perhaps you only need to recompile? I ran this code locally and it worked fine.

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();
                }
            }

OTHER TIPS

I had the same issue before. I had a SharePoint Project which referenced a class library. In .net 4.0 and above the DLLs are inserted at this location: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\. So, if you get the same error as the one above, then you need to rebuild your solution and deploy your DLL in the GAC_MSIL again otherwise it will still reference the old DLL.

In my case the issue is, I have changed the property type from string to int in library. and in an another project that property variable assigned to a dynamic variable while compiling it won't give any errors but at run time it will throw this errors. In order to solve this i need to compile the project which has dynamic variable assignment which doesn't have any changes. Now it works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top