List<string> not working

I had the following code working fine on one server:

List<string> equipment = new List<string>();

But after moving the page to another server I get this error:

Compiler Error Message: CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)

Any ideas? Thanks!

There is a using statement (a namespace) missing that was referenced on the other server.
Double check that ALL the files were moved AND are in the same relative place (so references to each other remained intact).

I added the following code to the top (which I didn’t need before):

<%@ Import Namespace="System.Collections.Generic" %>

Which eliminated the previous error, but when it gets the following code:

Response.Write("{ 'equipment' : [" + String.Join(",", equipment) + "] }");

It freaks out:

Compiler Error Message: CS1502: The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments

Is this something that could be referenced at the server level for all ASP pages? Because I never used a using statement before on the old server and it worked fine.

It looks like you did find the right Library reference (My experience with C# [desktop apps] it is ‘Using’ but with ASP.NET it is ‘Import’)

That error indicates the parameters of your ‘Join’ method are not all correct. What type is ‘equipment’? It needs to be an array of strings ( evidenced by the signature “string”)

equipment is built like this:

List<string> equipment = new List<string>();

And I add a string to it using the Add() method:

equipment.Add("{...JavaScript object...}");

And then attempt to spit it all out on the ASP page:

Response.Write("{ 'equipment' : [" + String.Join(",", equipment) + "] }");

Which, this works great on the old server. I’m at a loss at what’s missing.

When I do equipment.GetType() the output seems correct: System.Collections.Generic.List`1[System.String]

Old server was running 3.5 which has an overload of string.join which handles IEnumerable; you are going to need to convert the List<T> to an array to use it in the 2.0 server you are working on.

IIRC 3.5 also globally included System.Collections.Generic in the web.config so you didn’t need it on the pages.

Gotcha. Thanks for the info.