I have built a dll with csc.exe by using:
csc.exe "/target:library" "/out:$($path).dll" "$($path).cs"
From the powershell console I run it with:
powershell.exe -command {[byte[]]$bytes = [System.IO.File]::ReadAllBytes("$($args[0]).dll"); $assembly = [Reflection.Assembly]::Load($bytes); [ns.main]::Main();} -args $path
However when an exception occurs it just quits and prints nothing. I have to use try / catch in the code to trace down where it came from.
What do I have to change to get exceptions printed before it quits?
In the code I tried the event "UnhandledExceptionEventHandler" with AppDomain but that didnt work. You can however get the exception from the event log and $LASTEXITCODE is also set accordingly.
So I added this after the build and subsequent execution commands:
if ($LASTEXITCODE -ne 0)
{
Get-EventLog -logname Application -EntryType Error -source ".NET Runtime" -
Message *powershell* -newest 1| select-object -property timegenerated,message |
format-list
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.