views:

33

answers:

2

I have a MethodCallExpression object from which I'm trying to return a IObservable<Thing> instance using the Reactive Extensions framework.

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   Func<Thing> method = expression.Compile()
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   IObservable<Thing> observable = observable();
   return observable;
}

The issue is that when this executes I get the following runtime exception on observable():

 Could not load file or assembly 'System.CoreEx, Version=1.0.2617.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied.

If I run the method without the Reactive framework everything is fine.

 Thing item = method();

Any ideas what's causing this? All assembly references are added.

Edit I should add that the expression in question contains a method which executes on a Mocked object created using Moq.

A: 

Is reactive framework installed for the current user? do you have read/executable access to this file?

codymanix
Yes I'm using the reactive framework fine on it's own, it's only in this context.
TheCodeKing
A: 

Well I managed to get it working, although I never really got to the bottom of the Access Denied issue. It may have been a reboot that resolved it. After stripping my code right back and rebuilding it I starting getting a different error:

The object must be a runtime Reflection object

I then changed the code to wrap to method invoke into an Action before applying Rx, and this worked:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> = () => method();
   var observable = Observable.FromAsyncPattern<Thing>(method.BeginInvoke, method.EndInvoke);
   return observable();
}

For the record I was able to reduce this further:

private IObservable<Thing> GetThing(Expression<Func<Thing>> expression)
{
   var method = expression.Compile();
   Func<Thing> action = () => method();
   return Observable.Start(action);
}
TheCodeKing