开发者

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

Error 2 The type 'System.Data.DataTable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 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. You must add a reference to assembly 'System.Data, Ve开发者_如何学JAVArsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\Data\C#\IMSCF\IMSCF\frmPickList.cs 52 13 IMSCF

The 'var' keywords get highlighted by the last two errors.

I'm pretty new to C# and .NET CF so I don't really know what I'm doing wrong here; the code is adapted from something I found on a C# site somewhere.

Funny thing is, those references do exist in my project...all the right using statements are there etc...

Is there something here that .NET CF doesn't support (that's becoming a recurring theme in this project :P)

Thanks in advance.


You are using features of .net cf 3.5. Your headline says you're using .net cf 2.0. That's causing your problems.

More specifically:

  1. the Where method is part of LINQ. LINQ was introduced with .net cf 3.5.
  2. Lamba Expressions require .net cf 3.5
  3. Also, the var keyword is not part of .net 2.0.

So: either use .net cf 3.5 (recommended) or only use what 2.0 can handle.

(There's probably a technically better way to put it, but it boils down to 2.0 vs. 3.5)

EDIT: How to upgrade to 3.5:
In Visual Studio 2008 select Project from the menu, click on Upgrade Project and click Yes. That should be it.


Maybe you've a class library and the Windows Mobile application?

If so, have you checked that your class library has been created with the right Visual Studio template?

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.

Another thing you may check is maybe your Windows Mobile forms project is CF 3.5 while your class library is 2.0. Go to both project properties and check that target framework equals (you'd be using CF 3.5!!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜