Is there any different between these two csv file?

today i was trying to wrote two csv file to input data for my script

First csv file

x,y,z,name,type 
-820,50,-1580,ragni,
470,50,-1582,detlas,
100,50,-2200,Nemract,
-297,50,-1149,Tempo Town,
100,50,-3150,Selchar,
900,50,-2960,mage Islan,
855,50,-1963,Almuj,
105,50,-800,Nesaa,
-840,50,-920,Troms,
-700,50,-3100,Private Cove,
-2024,50,-4395,Llevigar,
-1448,50,-4725,Bucie,
-1732,50,-5528,Olux,
-1020,50,-5310,Gelibord,
-445,50,-4939,cinfras,
930,50,-5500,Eltom,
845,50,-5123,Thesead,
1211,50,-5190,rodoroc,
1460,50,-5278,Maex,
750,50,-4440,kandon-beda,
1050,50,-4600,Ahmsord,
88,50,-1200,Tower of Amnesia,
-1615,50,-2924,corkus City,
-1115,50,-2425,Legendary Island,
981,50,-704,Lutho,
1310,50,-1350,Rymek,

Second csv file :

x,y,z,name,type
-821,50,-1592,,potion merchant
-617,50,-1444,,potion merchant
453,50,-1595,,potion merchant
114,50,-2172,,potion merchant
93,50,-3167,,potion merchant
923,50,-1955,,potion merchant
862,50,-2873,,potion merchant
116,50,-778,,potion merchant
-189,50,-321,,potion merchant
-882,50,-943,,potion merchant
-611,50,-3063,,potion merchant
-1868,50,-4534,,potion merchant
-1735,50,-5492,,potion merchant
-1011,50,-5285,,potion merchant
-489,50,-4959,,potion merchant
758,50,-5045,,potion merchant
892,50,-5564,,potion merchant
1099,50,-5207,,potion merchant
1480,50,-8275,,potion merchant
749,50,-4476,,potion merchant
1121,50,-4549,,potion merchant
-552,50,-1582,,Identifier
-546,50,-1934,,identifier 
-628,50,-1400,,identifier 
468,50,-1585,,identifier 
140,50,-3172,,identifier 
1310,50,-1310,,identifier 
802,50,-3388,,identifier 
992,50,-3532,,identifier 
1136,50,-3116,,identifier 
88,50,-2181,,identifier 
-674,50,-324,,identifier 
-217,50,-324,,identifier 
91,50,-778,,identifier 
78,50,-345,,identifier 
-855,50,-897,,identifier 
-645,50,-1042,,identifier 
-1897,50,-4498,,identifier 
-1722,50,-5508,,identifier 
-1036,50,-5306,,identifier 
786,50,-5072,,identifier 
917,50,-5465,,identifier 
1035,18,-5109,,identifier 
1466,45,-5263,,identifier 
727,152,-4478,,identifier 
1077,50,-4548,,identifier 
-1593,68,-2943,,identifier 
-1610,38,-2360,,identifier 
-165,50,-1631,,powder Master
493,50,-1621,,powder Master
180,50,-2165,,powder Master
945,50,-1924,,powder Master
118,50,-191,,powder Master
-834,50,-941,,powder Master
-653,50,-3069,,powder Master
-1845,50,-4569,,powder Master
-1757,60,-5504,,powder Master
-1000,50,-5314,,powder Master
-461,50,-4969,,powder Master
779,50,-5063,,powder Master
1066,50,-5163,,powder Master
728,153,-4465,,powder Master
972,50,-4560,,powder Master
-1599,50,-2872,,powder Master
-1156,50,-2381,,powder Master
-866,50,-1560,,bank
-141,50,-1607,,bank
476,50,-1564,,bank    
90,50,-2205,,bank
983,50,-1956,,bank
1310,50,-1310,,bank
793,50,-3342,,bank
1142,50,-3114,,bank
106,50,-828,,bank
-217,50,-324,,bank
-701,31,-3085,,bank
21,50,-3202,,bank
-888,-918,,,bank
-664,50,-1036,,bank
981,73,-685,,bank
-2000,77,-4444,,bank
-1742,50,-5533,,bank
-1022,50,-5316,,bank
-435,50,-4929,,bank
144,50,-5256,,bank
805,94,-5035,,bank
978,50,-5487,,bank
1018,18,-5134,,bank
748,147,-4495,,bank
1065,59,-4548,,bank
-304,50,-4979,,bank
-1593,50,-2912,,bank
-1167,50,-2403,,bank


and i try to run

$places= Import-Csv C:\ex-sys\csv\map.csv
$places = [system.Collections.Generic.List[place]]$places

for the Second one it work well

but when i try to convert the first one it give the error
“InvalidArgument: Cannot convert the “System.Object” value of type “System.Object” to type “System.Collections.Generic.List`1[place]”.”

And i try to run the get-member of it
first one:

second one :

Entire class of [place] look like this



class distance {
   
    [string]$name
    [int]$distance

    distance (
    [string]$name,
    [int]$distance
    ) {
        $this.Name = $Name
        $this.distance= $distance
    
}

}

class address {
[string]$type
[int]$distance
[int]$x
[int]$y
[int]$z
    address(
    [string]$type,
    [int]$distance,
    [int]$X,
    [int]$y=50 ,
    [int]$z

)
{

    $this.type=$type
    $this.distance=$distance
    $this.x= $x
    $this.y= $y
    $this.z=$z
}

}
class place {
    [int]$x

    [int]$y

    [int]$z

    [string]$name

    [string]$type

    static [System.Collections.Generic.List[place]] $places

    place() { $this.Init(@{}) }


    
    place([hashtable]$Properties) { $this.Init($Properties) }

      # Shared initializer method
  [void] Init([hashtable]$Properties) {
    foreach ($Property in $Properties.Keys) {
        $this.$Property = $Properties.$Property
    }
}





static [int] calc (
[place]$place1,

[place]$place2


)
{
 return   ($place1.x-$place2.x )*($place1.x-$place2.x)+($place1.y-$place2.y)*($place1.y-$place2.y)+($place1.z-$place2.z)*($place1.z-$place2.z)

}



static [psobject] nearest(
[place]$place1,
[place]$place2



){
$distance = [place]::calc($place1,$place2)
return [distance]::new($place2.name,$distance)

}



static[psobject] find(
[place]$place1,
[place]$place2


)
{
   $distance = [place]::calc($place1,$place2)
   return [address]::new($place2.type,$distance,$place2.x,$place2.y,$place2.z)

}
   
static[psobject] add_town (
[System.Collections.Generic.List[place]] $places,

[place]$newplace
 )



{ 

    return $places + $newplace 
}

static [void] Validate([place]$newplace){

switch ($newplace.type ) {
    "Potion Merchant" {  }
    "BlackSmith"{ }
    "Scroll Merchant"{ }
    "Farm"{ }
    "Fishing"{ }
    "tool Merchant"{ }
    "cave"{ }
    "mine"{}
    "Bank"{}
    "Identifier"{}
    "chest" { }
    "powder master" { }
    Default {
throw $newplace.name + "is not  a valid type please try
-Potion Merchant
-BlackSmith
-Scroll Merchant
-Farm
-Fishing
-tool Merchant
-cave
-mine
-Identifier
-Bank
-chest
-powder master
"
   
    }
}
}

static [psobject]add_place (
    [System.Collections.Generic.List[place]] $places,
    [place]$newplace
    )

    
    {


    [place]::validate($newplace)
    return $places + $newplace 


}   

}

Yes, they are different in many ways. Different data. Different columns being used.

The question really your asking is why is one working and not the other, when they otherwise seem structurally the same. Well, they aren’t the same.

The way you copied it in, the column header type in the first file has a trailing space. If you fix that, it’ll fix your issues.

Yes
thanks a lot for the answering


i was trying to find anything wrong with my class and there is nothing and turn out it was a csv file mistake .
why is the csv file space causing the problem ,the powershell won’t ignore the space ,when i input the csv file the “type” meber actually become "type " member

Yep no problem. marking my answer as the solution.

Because your class doesn’t have a “${Type }” member. I bet if you change it to 'Type ’ in the class the opposite CSV will work while the working one ceases to.

sorry I missed the follow up question there, thanks for answering it.