Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

ResolveEventHandler and PowerShell

Closed Thread
 
Thread Tools Display Modes
Old 03-15-2008   #1 (permalink)
Justin Spindler
Guest


 

ResolveEventHandler and PowerShell

I am attempting to write some PowerShell scripts to help reflect over some
..NET assemblies. In order to enumerate the types of the loaded assemblies I
need to be able to handle the AppDomain.ReflectionOnlyAssemblyResolve event
which is of the delegate ResolveEventHandler with the following signature:

public Assembly ResolveEventHandler(object sender, ResolveEventArgs $e)

I know that $_ contains the ResolveEventArgs, but I can't seem to find a
suitable syntax to bind a script block to this delegate. I can only assume
that the problem is due to the return value of the delegate. I have tried
the following syntaxes:

$handler = [ResolveEventHandler] { return $null; }
$handler = [ResolveEventHandler] { return [Reflection.Assembly]$null; }
$handler = [ResolveEventHandler] { return
[Reflection.Assembly]::GetCurrentAssembly() }

All three fail that the script block could not be bound to the target
method. Is there an appropriate syntax for handling this kind of event that
I am missing?

Thanks,
Justin
Old 03-15-2008   #2 (permalink)
Oisin (x0n) Grehan [MVP]
Guest


 

Re: ResolveEventHandler and PowerShell

On Mar 15, 2:29*pm, Justin Spindler <jspind...@xxxxxx> wrote:
Quote:

> I am attempting to write some PowerShell scripts to help reflect over some
> .NET assemblies. *In order to enumerate the types of the loaded assemblies I
> need to be able to handle the AppDomain.ReflectionOnlyAssemblyResolve event
> which is of the delegate ResolveEventHandler with the following signature:
>
> public Assembly ResolveEventHandler(object sender, ResolveEventArgs $e)
>
> I know that $_ contains the ResolveEventArgs, but I can't seem to find a
> suitable syntax to bind a script block to this delegate. *I can only assume
> that the problem is due to the return value of the delegate. *I have tried
> the following syntaxes:
>
> $handler = [ResolveEventHandler] { return $null; }
> $handler = [ResolveEventHandler] { return [Reflection.Assembly]$null; }
> $handler = [ResolveEventHandler] { return
> [Reflection.Assembly]::GetCurrentAssembly() }
>
> All three fail that the script block could not be bound to the target
> method. *Is there an appropriate syntax for handling this kind of event that
> I am missing?
>
> Thanks,
> Justin
Hi Justin,

Unfortunately this syntax is not supported. The event support in v1 is
very basic, and can only handle void type delegates, and synchronous
events at that. The AssemblyResolve event is async and non-void as you
can see. Because async events are invoked on a non-powershell thread,
there is no runspace available to run the script because the default
runspace is kept in thread-local storage (TLS). I wrote an eventing
snapin for v1 that can handle async and sync events by using
background queue, but unfortunately it cannot handle non-void
delegates either.

- Oisin
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing PowerShell dependent features on W2K8 with PowerShell CTP Greg Wojan PowerShell 14 05-16-2008 08:15 AM
when run powershell script as windows service ,powershell fail powershell fail on winodws 2008 PowerShell 6 01-15-2008 03:20 PM
Powershell Plus - Free for non commercial Use and Powershell Analyzer1.0 released Karl Prosser[MVP] PowerShell 2 12-12-2007 12:43 PM
Automatic PowerShell Error Parsing in PowerShell Analyzer and PowerShellPlus Karl Prosser[MVP] PowerShell 0 11-14-2007 02:32 AM
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value klumsy@xtra.co.nz PowerShell 0 06-19-2007 02:42 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50