我有一个使用 VS2012 和 4.5 框架用 C# 编写的 Windows 服务。我的服务包含 2 个其他项目,这些项目基本上是我的数据库的对象,但它们使用 .edmx 文件和 EF5。
EDMX 项目:
MyCompany.Data.MasterDB
MyCompany.Data.StatsTracker
该服务对自身内部的方法进行了 2 次调用;1 生成要处理的文件列表,如果超过 0,则返回 true,否则返回 false.... 其他方法实际处理这些文件。
//Only proceed if there are files to process.
if (GenerateFileList())
ProcessLogs();
第二种方法(称为ProcessLogs
)是我尝试使用其他项目中的上下文的地方,并且是我收到以下错误的地方:
Method not found: 'System.Data.Entity.DbSet1<MyCompany.Data.MasterDB.StatisticLogType>MyCompany.Data.MasterDB.MasterDBContext.get_StatisticLogTypes()'.
下面是该方法的几行ProcessLogs
代码(这包含在 Try/Catch 中):
StatisticLogType duplicatesLogType;
StatisticLogType successLogType;
MasterDBContext scContext = new MasterDBContext();
StatsTrackerContext utContext = new StatsTrackerContext();
//I believe this is where the error is coming from:
successLogType = scContext.StatisticLogTypes
.Where(s => s.StatisticLogTypeID == (int)StatisticLogTypes.LogTypes.Success).FirstOrDefault<StatisticLogType>();
duplicatesLogType = scContext.StatisticLogTypes
.Where(s => s.StatisticLogTypeID == (int)StatisticLogTypes.LogTypes.Duplicates).FirstOrDefault<StatisticLogType>();
StatisticLogTypes.LogTypes
是驻留在MasterDB
对象中的静态枚举类:
public static class StatisticLogTypes
{
public enum LogTypes
{
CorruptFile = 1,
Success = 2,
Duplicates = 3,
LocationNotFound = 4,
SystemNotFound = 5,
BadFileNameFormat = 6,
Uploaded = 7,
FileNotFound = 8,
InvalidFileExtension = 9
}
}
对不起,它有点分散,但我尽量不遗漏任何东西......所以项目编译和构建成功,我什至可以使用 InstallShield Lite 安装它。当我运行它并将 VS 调试器附加到它时,我看到它通过该GenerateFileList()
方法很好,但是当我尝试通过ProcessLogs()
时,我得到了那个错误。它实际上并没有让我ProcessLogs()
逐行执行该方法,我觉得这很奇怪。
无论如何,我已经进行了大量研究试图找出问题所在,但似乎找不到任何东西。我已经确保我的所有项目都在同一个 .NET Framework 版本上,但这并没有帮助。
任何帮助或方向都会很棒。这让我很困惑,而且我这几天一直在努力寻找解决方案。
顺便说一句,我想补充一点,我在项目中添加了一个 TestUnit,并将服务中的所有逻辑都放入其中,并且能够毫无问题地运行它。