I am using T4Scaffolding to create a custom scaffold. I use the following PS code to get a list of all domain objects in my project:
# List of all domain classes. Get all top level files/folders in the project | drill down to Models folder | Enumerate ProjectItems | Where Name ends with .cs | Select name truncating .cs, pluralized name
$domainClasses = (Get-Project "Domain").ProjectItems | Where { $_.Name -eq "Models" } | ForEach { $_.ProjectItems } | Where { $_.Name.EndsWith('.cs') } | Select @{ Name = 'Name'; Expression={ $_.Name.SubString(0,$_.Name.Length - 3) } }, @{ Name = 'Plural'; Expression={ Get-PluralizedWord $_.Name.SubString(0,$_.Name.Length - 3) } }
if (!$domainClasses) { $domainClasses = @() }
Then I call the Add-ProjectItemViaTemplate method like this:
Add-ProjectItemViaTemplate $outputPath -Template MyTemplate `
-Model @{ DomainClasses=[Array]$domainClasses } `
-SuccessMessage "Added Domain output at {0}" `
-TemplateFolders $TemplateFolders -Project $DomainProjectName -CodeLanguage $CodeLanguage -Force:$Force
I get the following exception when I run the sacffold:
System.Runtime.Serialization.SerializationException: Type 'System.Management.Automation.PSCustomObject' in assembly 'System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
The problem seems to be that the $domainClasses variable can't be serialized for some reason. What am I doing wrong?