Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

'System.Collections.Generic.List<string>' does not contain a definition for 'Distinct'

3,217 views
Skip to first unread message

jc

unread,
Mar 25, 2009, 2:26:58 PM3/25/09
to
Sharepoint development.

I've added this inline code block to Sharepoint page.

I know the Web front end where it's running has .NET 3.0

<script runat="server">
protected void Page_PreRender(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Facilities"];
SPField field = list.Fields["Title"];
List<string> Titles = new List<string>();
foreach(SPListItem spli in list.Items)
{
Titles.Add(spli[field.Id].ToString());
}
Titles.Sort();
Titles.Distinct().ToList().ForEach(delegate(string code)
{
Facilities.Items.Add(new ListItem(code));
});
}
</script>

I'm getting this error:

'System.Collections.Generic.List<string>' does not contain a
definition for 'Distinct'


Thanks for any help or information.

Peter Duniho

unread,
Mar 25, 2009, 2:32:02 PM3/25/09
to
On Wed, 25 Mar 2009 11:26:58 -0700, jc <jo...@webdos.com> wrote:

> [...]


> I'm getting this error:
>
> 'System.Collections.Generic.List<string>' does not contain a
> definition for 'Distinct'

You need to compile with C# 3.0, against the .NET 3.5 libraries. The
Distinct() method you seem to be trying to use is one of the LINQ
extension methods. You need C# 3.0 for extension method support, and .NET
3.5 to get the LINQ Enumerable class.

Pete

jc

unread,
Mar 25, 2009, 4:30:32 PM3/25/09
to
Thank you..

Arne Vajhøj

unread,
Mar 25, 2009, 8:49:57 PM3/25/09
to

You will need .NET 3.5 and you will need to tell your web app
to use 3.5 when compiling.

You can add something like:

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
compilerOptions="/warnaserror-" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript"
extension=".vb" compilerOptions="/optioninfer+"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
</compiler>
</compilers>
</system.codedom>

to web.config.

Arne

jc

unread,
Mar 26, 2009, 12:27:52 PM3/26/09
to
We will eventually really want to do this, but we need to test .net
3.5 on a test farm first...

I was going to code a work around, but have an issue where I can't
even find my dropdownlist from my code block.. and SPD is not easy
for troubleshooting.

I've tried OnInit, OnLoad and OnPrerender.


protected void Page_OnInit(object sender, EventArgs e)


{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Facilities"];
SPField field = list.Fields["Title"];
List<string> Titles = new List<string>();
foreach(SPListItem spli in list.Items)
{

DropDownList fddl = (DropDownList)this.Page.FindControl
("FacilityDDL");
fddl.Items.Add("x");

// if (!fddl.Items.Contains(spli[field.Id].ToString()))
//if (fddl.Items.IndexOf(fddl.Items.FindByValue(spli
[field.Id].ToString())) =-1)
//{
//response.write("x");
// fddl.Items.Add(spli[field.Id].ToString());
//}
}
}
</script>

my asp.net control is inside:

<WebPartPages:DataFormWebPart


<asp:DropDownList runat="server" id="FacilityDDL"
DataTextField="Title" DataValueField="Title" /></td>

Am I missing something here?

0 new messages