How can I get PowerShell Added-Types to use Added Types

前端 未结 2 358
予麋鹿
予麋鹿 2021-01-03 05:35

I\'m working on a PoSh project that generates CSharp code, and then Add-Types it into memory.

The new types use existing types in an on disk DLL, which

2条回答
  •  滥情空心
    2021-01-03 05:40

    When you output the TestClassTwo to a dll (in the same directory as TestClassOne) and Add-Type it, it works. Or at least at my machine ;) So that's the ugly workaround.

    When calling $b.CallTestClassOne() PowerShell tries (from some reason I don't know) to find assembly TestClassOne.dll at these locations:

    LOG: Pokus o stažení nové adresy URL file:///C:/Windows/SysWOW64/WindowsPowerShell/v1.0/TestClassOne.DLL
    LOG: Pokus o stažení nové adresy URL file:///C:/Windows/SysWOW64/WindowsPowerShell/v1.0/TestClassOne/TestClassOne.DLL
    LOG: Pokus o stažení nové adresy URL file:///C:/Windows/SysWOW64/WindowsPowerShell/v1.0/TestClassOne.EXE
    LOG: Pokus o stažení nové adresy URL file:///C:/Windows/SysWOW64/WindowsPowerShell/v1.0/TestClassOne/TestClassOne.EXE
    

    This is output from fuslogvw tool. It might be useful for you. The same list of paths can bee seen live using ProcessMonitor.

    You might also try this (before calling CallTestClassOne()

    [appdomain]::CurrentDomain.add_assemblyResolve({
        $global:x = $args
    })
    $b.CallTestClassOne()
    $x | fl
    

    This will show you what assembly failed and some more info.

    I agree that it should work as you expect. So that's why this looks somewhat buggy.

提交回复
热议问题