Let me show you the Castle.Core generated code so you can see the exact 
point where async is missing

// Castle.Proxies.IMyServiceProxy
> public virtual Task<bool> GetResult()
> {
>     IMyService arg_19_0 = null;
>     IInterceptor[] arg_19_2 = this.__interceptors;
>     MethodInfo arg_19_3 = IMyServiceProxy.token_GetResult;
>     object[] array = new object[0];
>     IMyService_GetResult myService_GetResult = new IMyService_GetResult
> (arg_19_0, this, arg_19_2, arg_19_3, array);
>     myService_GetResult.Proceed();
>     return (Task<bool>)myService_GetResult.get_ReturnValue();
> }
>

I'm not sure if I mentioned that I have an async call just before you call "
*invocation.Proceed();*" and that is manifesting as described below.

This line "*myService_GetResult.Proceed();*" is causing an issue because 
this method calls interceptor's Intercept method and inside that method you 
have an async method awaiting for result. But then control is returned back 
to caller which is "*myService_GetResult.Proceed();*" and it's not 
awaiting, next line will require a Task<bool> to be returned but 
get_ReturnValue() is null. The rest of your code seems fine.

Let me know if you have any ideas how to overcome this ?

Thanks

On Thursday, July 18, 2013 7:02:29 AM UTC+2, Mauricio Scheffer wrote:
>
> Not sure I understand completely what you're trying to do, but can't you 
> just do something like this?
>
>     internal class Program {
>         private static void Main(string[] args) {
>             var generator = new ProxyGenerator();
>             var c = generator.CreateClassProxy<AsyncClass>(new 
> AsyncInterceptor());
>             var x = c.GetSomething().Result;
>             Console.WriteLine(x);
>         }
>     }
>
>     public class AsyncClass {
>         public virtual async Task<string> GetSomething() {
>             var h = new HttpClient();
>             var response = await h.GetAsync("http://www.google.com";);
>             var content = await response.Content.ReadAsStringAsync();
>             return content;
>         }
>     }
>
>     public class AsyncInterceptor : IInterceptor {
>         public async void Intercept(IInvocation invocation) {
>             invocation.Proceed();
>             var result = await (Task<string>)invocation.ReturnValue;
>             invocation.ReturnValue = Task.Factory.StartNew(async () => {
>                 var h = new HttpClient();
>                 var response = await h.GetAsync("http://www.bing.com";);
>                 var content = await response.Content.ReadAsStringAsync();
>                 return content + result;
>             });
>         }
>     }
>
> Cheers
>
>
>
> --
> Mauricio
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/castle-project-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to