I was struck by this myself, and for various reasons I can not upgrade projects to .NET 4.5, so I had to develop a workaround.
Since this is only a problem for XAML projects that has an xmlns
declaration pointing to itself, I can use async for all other referenced projects. This means that my architecture is still using async / await and is ready to migrate to .NET 4.5 later.
But in the affected XAML projects, I simply manually (poorly) implement things that are otherwise executed by the compiler.
So, the code that was previously clean:
try { var foo = GetFoo(); foo.DoStuff(); var data = await foo.GetDataAsync(); bar.WorkOnData(data); } catch (Exception ex) {
Now it will be as follows:
var foo = GetFoo(); foo.DoStuff(); var getDataTask = foo.GetDataAsync(); getDataTask.ContinueWith(t => { if (t.IsFaulted) {
Not ideal, of course, and this is what async/await
was created for the solution. But this works as a short-term workaround, at least for the simple use of await
.
source share