0

I working with some API that need to run with async (an await in body also) but it throw an exception like this:

System.NullReferenceException: Object reference not set to an instance of an object.

when I call that api without define defaultProxy in WebConfige. But in my solution I cannot define defaultProxy because it will interrupt some other process.

I also read this post but cannot find the solution :(

So do we have anyway to run the async method without await like create background thread to run some method like ReadAsStreamAsync (just an example).

Community
  • 1
  • 1
Bui Quang Huy
  • 1,636
  • 2
  • 13
  • 44
  • Please take a look here : http://stackoverflow.com/q/4660142/3956100 – Niklas Sep 23 '16 at 04:32
  • Also here: http://stackoverflow.com/help/how-to-ask – Niklas Sep 23 '16 at 04:32
  • 1
    Simple, `Null reference exception` is due to attempt to use a `Null` object to call a method, which will never work. `Async-Await` doesn't create background thread. You can wrap a Synchronous method like `ReadAsStream` in a `Task` like `Task.Run(() => ReadAsStream())`, which will still return `awaitable Task`, but doesn't need `Async` method – Mrinal Kamboj Sep 23 '16 at 04:45
  • Yes I know it, but the main issue here is the async just run when I have default proxy. Not about the exception at all. Please read my question carefully :| – Bui Quang Huy Sep 23 '16 at 06:01
  • @MrinalKamboj Maybe I will go with that way – Bui Quang Huy Sep 23 '16 at 06:01
  • @BuiQuangHuy You have highlighted the exception, how carefully shall I read, you need to highlight the main question instead :). Nonetheless I have provided you the solution to get that working using simple task API – Mrinal Kamboj Sep 23 '16 at 06:13

0 Answers0