Corrado's Blog 2.0

Online thoughts of a technology funatic

The remote procedure call failed. Exception from HRESULT: 0x800706BE issue in Windows Store apps

There are days where technology seems to be against you, yesterday was one of those.

It all started in the morning when I inadvertently pressed the sleep button on my Logitec keyboard and my notebook gone into sleep mode, something i do often indeed, but this time it was different because at resume all i got was a black screen. Since this happened a couple of times in the past I switched it off hoping to solve it soon, but after machine boot the black screen was still there. A voice inside of me started saying “is gonna be a hard day…”, so i started, without much faith honestly the: boot, safe mode, repair, try restore point ritual but, as always happened in my personal experience, without luck.

Since I really hate repaving my work machine, I’m a bit paranoid with backups: I do backup at least once/twice a week and before any important update. so I inserted the USB recovery key of my favorite’s backup tool: Acronis True Image and started a sector-by-sector restore of July 28th backup.

After a while my notebook was brought back to life, and nobody will ever know what happened on this bright July 30th morning, but who cares, it’s time to go back coding…

Since I’m working on a Windows Store app that interacts with Facebook I started digging into Facebook SDK documentation and in short time I wrote a test app that logins and retrieves user profile.

Time to test the code: I lanched the app, the login dialog appeared and successfully logged in, but, wait, there’s a an issue: the breakpoint I added to read the returned token didn’t fired and application seems never returning from Login method.

Ok, let’s find what’s wrong but starting from Facebook developer registration down to code everything looks fine.

Let’s try an old sample I wrote in the past I know was ok: same problem.

Let’s use WebAuthenticationBroker sample from Developer portal, it must work!: well it wasn’t.

Since I lost any idea I asked my friend @CristianCivera some hints and you can image my face when after some pair debugging he told me: “Know what? the sample works on my machine

Below my face as soon as I read the message:

Also my friend @imperugo confirmed: The only machine on earth where the WebAuthenticationBroker.AuthenicateAsync() method was not returning was mine…

Just to be 100% sure I started a remote debugging session with my tablet and everything was working as expected.

I started to getting nervous since I had no idead why that call wasn’t working on my PC.

While trying to find a solution i thought: And if problem isn’t in just WebAuthenticationBroker but in all async methods? So I opened the FilePicker example from Windows Store dev portal, launched it and put a breakpoint on yellow line:

image

Result: I can select the file, breakpoint doesn’t fire anyway,  but now Visual Studio reports an exception:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)"}

a search on Interned pointed me to several possible solutions but none was the right one, looks like async call for unknown reason never returns, even launching the standalone app..

I started realizing that can’t work on any Windows Store app until I get this fixed and wondered: Why didn’t got into this before?, I spend the day between async/await and breapoints always worked.

Tried another Windows Store app that uses async/await and breakpoints worked, so why some async calls raise the exception and others don’t?

After long thinking I realized that both OpenPicker.PickSingleFileAsync() and WebAuthenticationBroker.LoginAsync() deal with UI, former opens file selection while latter displays a dialog, so I started thinking about graphic drivers (don’t ask me why, maybe someone took pity on me…) so I updated my NVidia driver and restarted.

No way, problem still there…

Before starting to tear my hair (and remind me that I do not have…) i remembered that I also have a USB video driver that controls my 3rd monitor: A quick check and saw that it driver was outdated, so i installed the recent one. Rebooted the machine launched the sample and…

YESSSSSS!!! The problem gone! probably something in the driver was conflicting with WinRT causing the exception thus preventing the call to return.

To recap this long post: If your async calls seems not to return and you get weird: The remote procedure call failed. (Exception from HRESULT: 0x800706BE)" message: check your video drivers.

If all this sound unbeliveable, you’re right, IT IS! (while true…)

Hope this will save you working hours (and hairs) in future.

Exception deriving from WebClient on Windows Phone 7.5

I was working on a Windows Phone 7.5 app that requires to use WebClient class to post a HEAD request to the server, since WebClient doesn’t support it, i used the trick to derive from WebClient and override the GetWebRequest method.

public class WebClientEx : WebClient
        {            
            public WebClientEx()
            {
            }
            
            public string Method
            {
                get;
                set;
            }

            protected override WebRequest GetWebRequest(Uri address)
            {
                WebRequest webRequest = base.GetWebRequest(address);

                if (!string.IsNullOrEmpty(Method))
                    webRequest.Method = Method;

                return webRequest;
            }
        }

i then used the new class this way:

WebClientEx client = new WebClientEx() { Method = "HEAD" };
client.DownloadStringCompleted += (s, e) => ...
client.DownloadStringAsync(new Uri(uri, UriKind.Absolute));

Nothing new indeed, so what is the reason of this post? the fact that everything was fine in Windows Phone 8 but it was failing with a “inheritance security rules violated by type WebClientEx. Derived types must either  match the security accessibility of the base type or be less accessible.  If the base class has a non-transparent default constructor, the derived class must also have a default constructor, and the method inheritance rules apply across those two methods.”  when run on a Windows Phone 7.5 device.

A quick search and it looks like that the reason comes from a missing attribute applied to derived class constructor.

Adding a default constructor marked with SecuritySafeCritical attribute solved it (Phew!)

[System.Security.SecuritySafeCritical]
public WebClientEx()
{
}