1

I'm writing a powershell script on Microsofts WHCK 2.0 API. I'm from perl background so do not know much in powershell or c#.

Well, my code 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.

   $List = New-Object "System.Collections.Generic.List``1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]"

When I run this code, it produces this error:

"New-Object: Cannot find type: [System.Collections.Generic.List`1[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]]: make sure the aseembly containing this type is loaded."

I've verified that the aseemblies are loaded correctly, using CurrentDomain.getAssemblies() method. Also I have verified that the type "Microsoft.Windows.Kits.Hardware.ObjectModel.Target" is present in "Microsoft.Windows.Kits.Hardware.ObjectModel.dll" assembly, as:

$ObjectModel.GetTypes() | % { 
      if($_.FullName -eq "Microsoft.Windows.Kits.Hardware.ObjectModel.Target")
      { 
          $found=1
      }
}

One more thing I would like to mention, "Microsoft.Windows.Kits.Hardware.ObjectModel.Target" this type/class is an abstract class.

I've searched a lot but couldnt get the right way to get rid of this error. Please suggest and help overcoming this error.

Echilon
  • 10,064
  • 33
  • 131
  • 217

1 Answers1

1

try this:

$List = New-Object 'System.Collections.Generic.List[Microsoft.Windows.Kits.Hardware.ObjectModel.Target]'
CB.
  • 58,865
  • 9
  • 159
  • 159
  • Hi Christian, tried that too, but getting same error. Tried this: $List=New-Object 'System.Collections.Generic.List``1[System.Object]' and it worked. But when I replace "System.Object" with "Microsoft.Windows.Kits.Hardware.ObjectModel.Target", it doesnt work. :( – Nilesh Mali Nov 09 '12 at 10:25
  • If you do `$a = new-obect 'Microsoft.Windows.Kits.Hardware.ObjectModel.Target'` got some error? – CB. Nov 09 '12 at 10:33
  • yes, there is an error: "New-Object: Constructor not found. Cannot find an appropriate constructor for type microsoft.windows.kits.hardware.objectmodel.target" – Nilesh Mali Nov 09 '12 at 10:38
  • Check out the sample script microsoft has provided in WHCK documentation, at "http://msdn.microsoft.com/en-us/library/windows/hardware/jj123504.aspx#BKMK_PS_CreateSubmissionPackage" under Windows Powershell section and under heading "Create a submission package from a project". When I asked Microsoft people about this error, they said it is working fine at their side, so whats wrong at my side, i'm not getting that. – Nilesh Mali Nov 09 '12 at 10:57
  • In the link I see just `$targetList = New-Object "System.Collections.Generic.List``1[Target]"` ... have you tried like this? – CB. Nov 09 '12 at 11:05
  • Do I need to do Add-type on this type, i.e. 'Microsoft.Windows.Kits.Hardware.ObjectModel.Target' ? – Nilesh Mali Nov 14 '12 at 16:27