3

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

03Usr
  • 3,335
  • 6
  • 37
  • 63

3 Answers3

2

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();
                }
            }
Bill Gregg
  • 7,067
  • 2
  • 22
  • 39
  • 7
    @03Usr, if it didn't work for you, it should not have been accepted. SO is about getting *correct* answers, not "best answers in a certain timeframe even if they don't work" :-) – paxdiablo Mar 14 '16 at 03:30
2

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.

Divi
  • 7,621
  • 13
  • 47
  • 63
Imir Hoxha
  • 1,674
  • 6
  • 31
  • 56
0

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.

Gokul
  • 1
  • 1
  • 2