C# System.MissingMethodException:找不到方法:'System.String .get_DayName()'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16651784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.MissingMethodException: Method not found: 'System.String .get_DayName()'
提问by 03Usr
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:
我正在创建一个包含 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:
我正在使用以下内容将 TimeBands 加载到另一个列表中:
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 DayNameproperty to DayOfWeekfrom stringso the code has become like this:
这工作正常,但在 TimeBand 类中,我决定将DayName属性的类型从字符串更改为DayOfWeek,因此代码变成了这样:
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.Whereline and giving the following error: System.MissingMethodException: Method not found: 'System.String TimeBand.get_DayName()'.
这个新代码现在在TimeBandList.Where行上失败 并给出以下错误:System.MissingMethodException: Method not found: 'System.String TimeBand.get_DayName()'。
Any idea why?
知道为什么吗?
Thanks
谢谢
采纳答案by Bill Gregg
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();
}
}
回答by Imir Hoxha
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.
我之前也遇到过同样的问题。我有一个引用类库的 SharePoint 项目。在 .net 4.0 及更高版本中,DLL 被插入到以下位置:C:\Windows\Microsoft.NET\assembly\GAC_MSIL\. 因此,如果您遇到与上述相同的错误,那么您需要重建您的解决方案并再次在 GAC_MSIL 中部署您的 DLL,否则它仍将引用旧的 DLL。
回答by Gokul
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.
就我而言,问题是,我已将库中的属性类型从 string 更改为 int。在另一个项目中,属性变量在编译时分配给动态变量不会给出任何错误,但在运行时会抛出此错误。为了解决这个问题,我需要编译具有动态变量分配的项目,该项目没有任何更改。现在它工作正常。

