File tree Expand file tree Collapse file tree 1 file changed +35
-4
lines changed
Expand file tree Collapse file tree 1 file changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -194,10 +194,41 @@ class SqlResourceBase : ResourceBase
194194
195195 if (-not $enumType )
196196 {
197- # Try loading from loaded assemblies if direct resolution fails.
198- $enumType = [System.AppDomain ]::CurrentDomain.GetAssemblies().GetTypes() |
199- Where-Object - FilterScript { $_.FullName -eq $fullTypeName } |
200- Select-Object - First 1
197+ <#
198+ Try loading from loaded assemblies if direct resolution fails.
199+ Must iterate through assemblies individually and handle
200+ ReflectionTypeLoadException because some assemblies contain
201+ types that cannot be loaded (e.g., SqlGuidCaster from
202+ Microsoft.Data.SqlClient), causing GetTypes() to fail. When
203+ the exception occurs, use the Types collection from the
204+ exception which contains the types that were successfully
205+ loaded (with $null entries for failed types).
206+ #>
207+ foreach ($assembly in [System.AppDomain ]::CurrentDomain.GetAssemblies())
208+ {
209+ try
210+ {
211+ $enumType = $assembly.GetTypes () |
212+ Where-Object - FilterScript { $_.FullName -eq $fullTypeName } |
213+ Select-Object - First 1
214+
215+ if ($enumType )
216+ {
217+ break
218+ }
219+ }
220+ catch [System.Reflection.ReflectionTypeLoadException ]
221+ {
222+ $enumType = $_.Exception.Types |
223+ Where-Object - FilterScript { $null -ne $_ -and $_.FullName -eq $fullTypeName } |
224+ Select-Object - First 1
225+
226+ if ($enumType )
227+ {
228+ break
229+ }
230+ }
231+ }
201232 }
202233
203234 if ($enumType )
You can’t perform that action at this time.
0 commit comments