SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question List<string> not working

    I had the following code working fine on one server:

    Code:
    List<string> equipment = new List<string>();
    But after moving the page to another server I get this error:

    Code:
    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!

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,336
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    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).
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added the following code to the top (which I didn't need before):

    Code:
    <%@ Import Namespace="System.Collections.Generic" %>
    Which eliminated the previous error, but when it gets the following code:

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

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

  4. #4
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    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).
    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.

  5. #5
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,336
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by NokX View Post
    I added the following code to the top (which I didn't need before):

    Code:
    <%@ Import Namespace="System.Collections.Generic" %>
    Which eliminated the previous error, but when it gets the following code:

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

    Code:
    Compiler Error Message: CS1502: The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments
    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[]")
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  6. #6
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    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:

    Code:
    List<string> equipment = new List<string>();
    And I add a string to it using the Add() method:

    Code:
    equipment.Add("{...JavaScript object...}");
    And then attempt to spit it all out on the ASP page:

    Code:
    Response.Write("{ 'equipment' : [" + String.Join(",", equipment) + "] }");
    Which, this works great on the old server. I'm at a loss at what's missing.

  7. #7
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ParkinT View Post
    What type is 'equipment'? It needs to be an array of strings ( evidenced by the signature "string[]")
    When I do equipment.GetType() the output seems correct: System.Collections.Generic.List`1[System.String]

  8. #8
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,633
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wwb_99 View Post
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •