none
Error creating "System.Collections.Generic.List`1" collection object which will have have each element in collection of type "Microsoft.Windows.Kits.Hardware.ObjectModel.Target" RRS feed

  • Question

  • <p>Hello,</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I'm getting an error while&nbsp;creating collection object of class "System.Collections.Generic.List`1"&nbsp;&nbsp;of type "Microsoft.Windows.Kits.Hardware.ObjectModel.Target" in powershell</p>
    Tuesday, October 30, 2012 11:11 AM

Answers

All replies

  • Can you please provide the actual error message being returned?

    Paul - This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, October 30, 2012 7:14 PM
  • Hi Paul,

    An error is as below:

    New-Object : Cannot find type [System.Collections.Generic.List`1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]]: make sure the assembly containing this type is loaded.
    At scriptpath.ps1:531 char:25
    +     $targetList =new-object <<<<  "System.Collections.Generic.List``1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
        + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

    Wednesday, October 31, 2012 9:39 AM
  • We can't tell from this which type (the list, or the target) is not being resolved?

    can you try to create a generic list (of say string) AND a OM.Target, to see which object type is not being resolved

    more information would also be appreciated, possibly more pertinent details of what you are trying to do?

    Wednesday, October 31, 2012 3:54 PM
  • Hi Jeff,

    Well, short Algorithm on what i want to do, goes here:

    1) create a collection object as:

    $targetList =new-object "System.Collections.Generic.List``1 [Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"

    2) Get all product instances, and for each product instance do-

           a) Get all the targets in current product instance

           b) for each target do-

                    i) if current target is the required one then-

                             - Add it to the collection created in step 1) as, $targetList.Add($target)

    3) once $targetList is prepared, I will pass it to AddDriver() method as-

    AddDriver($driverpath,$null,$targetList,$localeList,[ref] $errormsgs,[ref] $warningmsgs)

    ==end of algorithm

    I'm getting an error in step 1), for which this thread is running.

    I tried, $targetList =new-object "System.Collections.Generic.List``1 [System.Object]", it worked fine, even I was able to iterate through this $targetList array printing names of the targets. But when I passed this variable to AddDriver() method, I got other error, it was something like this:

    Cannot convert object of type [System.Object] to type [Microsoft.Windows.Kits.Hardware.ObjectModel.Target]


    • Edited by Nilesh90 Thursday, November 1, 2012 12:12 PM
    Thursday, November 1, 2012 11:02 AM
  • So the Target type is not being resolved.
    Thursday, November 1, 2012 12:18 PM
  • what I have; that's working for me is


    $ObjectModel  = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dll")
    $DbConnection = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll")
    $Submission   = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.submission.dll")
    
    
    # And a little bit later.
    
        $targetList = New-Object "System.Collections.Generic.List``1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"
                
        $Project.GetProductInstances() | foreach {
            $targetlist.AddRange($_.GetTargets())
            }     
    So I guess that you should make sure that the assemblys are being loaded correctly.

    Thursday, November 1, 2012 5:49 PM
  • Hi jeff,

    All the other functionality exposed by these assemblys are working fine. I'm able to create project, machine pool, product instances, adding targets, running tests, etc. So we can conclude that aseemblys are loaded correctly, can't we?

    I simply copied your code and ran it, but getting the same error.

    May I know which version of .Net and Powershell you are running this code on?

    On my system I have powershell v1.0 and .Net version which comes with WHCK 2.0 installation.

    Friday, November 2, 2012 7:34 AM
  • Hi,

    The code is pasted here, I'm getting an error in first statement of GetAllSelectedTargets() fuction

    Please suggest if anything is wrong here. Also the assemblies are loaded correctly, I have verified them using CurrentDomain.getAssemblies() method.

    $ObjectModel = [Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Windows Kits\8.0\Hardware Certification Kit\Studio\microsoft.windows.Kits.Hardware.objectmodel.dll')
    $DBConnection = [Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Windows Kits\8.0\Hardware Certification Kit\Studio\microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll')
    $Submission = [Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Windows Kits\8.0\Hardware Certification Kit\Studio\microsoft.windows.Kits.Hardware.objectmodel.submission.dll')

    Function GetAllSelectedTargets($projectObject)
    {
     $targetList =new-object "System.Collections.Generic.List``1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"
     $piList=$projectObject.GetProductInstances() # get all the PI's available in this Project
     foreach ($pi in $piList)
     {
      $targetlist.AddRange($pi.GetTargets()) # get all the targets present in this PI
     }
     return($targetList)
    }

    Function AddDriverTarget($projectObject,$packageWriter,$driverPath)

     $targets=GetAllSelectedTargets $projectObject
     
     $localeList = New-Object "System.Collections.Generic.List``1[System.string]"
     $localeList.AddRange([microsoft.windows.Kits.Hardware.objectmodel.projectmanager]::GetLocaleList())
     
     $errorMessages = New-Object "System.Collections.Specialized.StringCollection"
     
        $warningMessages = New-Object "System.Collections.Specialized.StringCollection"
     
     $status=$packageWriter.AddDriver($driverPath, $null, $targets.AsReadOnly(), $localeList.AsReadOnly(), ([ref] $errorMessages), ([ref] $warningMessages))
     if($status -eq $false)
     {
      Write-Host "Add driver failed to add this driver found at : $driverPath"
            foreach ($errMsg in $errorMessages) 
            {
                Write-Host "Error: "$errMsg            
            }
     }
     if ($warningMessages.Count -ne 0)
        {
            Write-Host "Add driver found warnings in the package found at : $driverPath"
            foreach ($warnMsg in $warningMessages)
            {
                Write-Host "Warning: "$warnMsg
            }
        }
    }

    Monday, November 5, 2012 10:02 AM
  • Saturday, November 17, 2012 1:58 AM
    Moderator
  • No, that isn't an answer. the list isn't the problem, it's the target not resolving and I think we are all using ` instead of '
    Monday, November 19, 2012 5:45 PM
  • Yes, Mike is right.

    I have used this:
    $targetlist=new-object "system.collections.generic.list``1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"

    but it produces an error.

    When I use this:

    $targetlist=new-object "system.collections.generic.list``1[System.Object]"

    It works, but later on, when I pass "$targetlist.AsReadOnly" as an argument to the $packageWriter.AddDriver() method it produces some other error:

    Cannot convert argument "2", with value: "System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]", for "AddDriver" to type "System.Collections.Generic.IEnumerable`1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]": "Cannot convert the "System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]" value of type "System.Collections.ObjectModel.ReadOnlyCollection`1[[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" to type "System.Collections.Generic.IEnumerable`1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"."
    At D:\Scripts\create_project.ps1:509 char:34
    +     $status=$packageWriter.AddDriver <<<< ($driverPath, $null, $targetList.AsReadOnly(), $localeList.AsReadOnly(), ([ref] $errorMessages), ([ref] $
    warningMessages))
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    Monday, December 3, 2012 7:56 AM
  • Updated powershell to 3.0, as suggested in the thread initiated by "Mike Bagdanoff".

    All issues are resolved. :)

    Thursday, December 6, 2012 7:50 AM