Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overcome Windows Component limitation to windows runtime types?

I have a Windows Store application that uses a background task. The background task is stored in a Windows Runtime Component project. (This structure appears to be the only way to make background tasks work.)

In the background task project, I have some externally visible public methods that have return/parameter types that are my own classes rather than Windows Runtime classes.

For example:

public MyClass DoSomething()
{
    return null;
}

When I build, I receive errors such as the following in relation to these methods:

Method 'X' returns 'Y', which is not a valid Windows Runtime type. Methods exposed to Windows Runtime must return only Windows Runtime types.

and

Method 'T' has parameter 'U' of type 'W'. 'W' is not a valid Windows Runtime parameter type.

I can understand what the errors are saying, but I haven't thought of a good way I can structure my code so that I meet these requirements.

Here are some things I have already considered:

  1. Changing the background task project to a Windows Store Class Library project. This allowed the use of the non-Windows Runtime types in the method signatures, but the background task no longer launched.
  2. Using a portable class library. This didn't work because it didn't have access to the Windows Runtime.
  3. For value types, I can break them up into Tuples or multiple parameters, but this seems messy, less structured and less maintainable. I am strongly against this type of programming.
  4. For classes, it seems that I might have to duplicate their logic across both applications. This is a huge maintainability problem.
like image 903
Sam Avatar asked Mar 01 '13 21:03

Sam


1 Answers

I was able to make this work by isolating the background task in a Windows Component project and moving the re-usable Windows Runtime-dependent code into a Windows Store Class Library project.

like image 117
Sam Avatar answered Nov 08 '22 06:11

Sam