简体   繁体   English

C#/ Compact Framework 2.0 /清单查询错误

[英]C# / Compact Framework 2.0 / List query error

OK so I have: 好,所以我有:

var filteredItems = lstAllItems.Where(item => item.Parent.ID == parentId);

TreeNode childNode;
    foreach (var i in filteredItems.ToList())
    {
        if (parentNode == null)
            childNode = tvwPickList.Nodes.Add(i.Text);
        else
            childNode = parentNode.Nodes.Add(i.Text);

        RefreshPickList(i.ID, childNode);
    }

This is throwing some errors at me: 这给我带来了一些错误:

Warning 1 Reference to type 'System.Runtime.Serialization.SerializationInfo' claims it is defined in 'c:\\Program Files (x86)\\Microsoft.NET\\SDK\\CompactFramework\\v2.0\\WindowsCE\\mscorlib.dll', but it could not be found c:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Data.DataSetExtensions.dll IMSCF 警告1引用类型'System.Runtime.Serialization.SerializationInfo'声称它是在'c:\\ Program Files(x86)\\ Microsoft.NET \\ SDK \\ CompactFramework \\ v2.0 \\ WindowsCE \\ mscorlib.dll'中定义的,但是它找不到c:\\ Program Files(x86)\\ Reference Assemblies \\ Microsoft \\ Framework \\ v3.5 \\ System.Data.DataSetExtensions.dll IMSCF

Error 2 The type 'System.Data.DataTable' is defined in an assembly that is not referenced. 错误2在未引用的程序集中定义了类型'System.Data.DataTable'。 You must add a reference to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 您必须添加对程序集'System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用。 C:\\Data\\C#\\IMSCF\\IMSCF\\frmPickList.cs 52 13 IMSCF C:\\ Data \\ C#\\ IMSCF \\ IMSCF \\ frmPickList.cs 52 13 IMSCF

Error 3 The type 'System.Data.DataRow' is defined in an assembly that is not referenced. 错误3类型'System.Data.DataRow'是在未引用的程序集中定义的。 You must add a reference to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 您必须添加对程序集'System.Data,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的引用。 C:\\Data\\C#\\IMSCF\\IMSCF\\frmPickList.cs 52 13 IMSCF C:\\ Data \\ C#\\ IMSCF \\ IMSCF \\ frmPickList.cs 52 13 IMSCF

The 'var' keywords get highlighted by the last two errors. 最后两个错误会突出显示“ var”关键字。

I'm pretty new to C# and .NET CF so I don't really know what I'm doing wrong here; 我对C#和.NET CF还是很陌生,所以我真的不知道我在做什么错。 the code is adapted from something I found on a C# site somewhere. 该代码改编自我在C#网站上某个地方找到的内容。

Funny thing is, those references do exist in my project...all the right using statements are there etc... 有趣的是,这些引用确实存在于我的项目中...所有正确的using语句都存在等...

Is there something here that .NET CF doesn't support (that's becoming a recurring theme in this project :P) .NET CF这里不支持某些功能(这在该项目中成为重复出现的主题:P)

Thanks in advance. 提前致谢。

You are using features of .net cf 3.5. 您正在使用.net cf 3.5的功能。 Your headline says you're using .net cf 2.0. 您的标题是您正在使用.net cf 2.0。 That's causing your problems. 那就是你的问题。

More specifically: 进一步来说:

  1. the Where method is part of LINQ. Where方法是LINQ的一部分。 LINQ was introduced with .net cf 3.5. LINQ是在.net cf 3.5中引入的。
  2. Lamba Expressions require .net cf 3.5 Lamba表达式需要.net cf 3.5
  3. Also, the var keyword is not part of .net 2.0. 另外, var关键字也不是.net 2.0的一部分。

So: either use .net cf 3.5 (recommended) or only use what 2.0 can handle. 因此:要么使用.net cf 3.5(推荐),要么仅使用2.0可以处理的内容。

(There's probably a technically better way to put it, but it boils down to 2.0 vs. 3.5) (可能有一种技术上更好的放置方式,但归结为2.0对3.5)

EDIT: How to upgrade to 3.5: 编辑:如何升级到3.5:
In Visual Studio 2008 select Project from the menu, click on Upgrade Project and click Yes . 在Visual Studio 2008中,从菜单中选择“ 项目 ”,单击“ 升级项目” ,然后单击“ 是” That should be it. 应该是这样。

Maybe you've a class library and the Windows Mobile application? 也许您有一个类库和Windows Mobile应用程序?

If so, have you checked that your class library has been created with the right Visual Studio template? 如果是这样,您是否检查了是否已使用正确的Visual Studio模板创建了类库?

You'll need to create such class library with Mobile Visual Studio-installed templates, because it seems that you did with the regular C# class library one, which adds namespaces that aren't pressent in CF. 您需要使用安装了Mobile Visual Studio的模板来创建这样的类库,因为您似乎使用了常规的C#类库,它添加了CF中没有压力的名称空间。

Another thing you may check is maybe your Windows Mobile forms project is CF 3.5 while your class library is 2.0. 您可能要检查的另一件事是,您的Windows Mobile表单项目是CF 3.5,而类库是2.0。 Go to both project properties and check that target framework equals (you'd be using CF 3.5!!). 转到两个项目属性,并检查目标框架是否相等(您将使用CF 3.5!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM