0

I've suddenly got a problem with a script that has been running without problems previously

$sln = 'D:\[...]\[...].sln'
Add-Type -Path (${env:ProgramFiles(x86)} + '\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Microsoft.Build.dll')
$slnFile = [Microsoft.Build.Construction.SolutionFile]::Parse($sln)

The Add-Type seems to work without an error, but the next line keeps throwing an error

Unable to find type [Microsoft.Build.Construction.SolutionFile].
At D:\[...]\[scriptname].ps1:7 char:13
+     $slnFile = [Microsoft.Build.Construction.SolutionFile]::Parse($sl ...
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Build...on.SolutionFile:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

The script was based on several examples

And it worked in the past. I'm still pointing to the same old Microsoft.Build.dll assembly. Can anybody explain to me what's changed?

JHBonarius
  • 10,824
  • 3
  • 22
  • 41
  • Perhaps you can find out more if you do ``try{ Add-Type -Path ""} catch [System.Reflection.ReflectionTypeLoadException] { "Message: $($_.Exception.Message)`r`nStackTrace: $($_.Exception.StackTrace)`r`nLoaderExceptions: $($_.Exception.LoaderExceptions)"}`` – Theo Dec 11 '20 at 11:00
  • @Theo that gives no result. The Add-Type seems to work. I also see the assembly in the list when I run `[System.AppDomain]::CurrentDomain.GetAssemblies()`. – JHBonarius Dec 11 '20 at 12:08

0 Answers0