Answered by:
the template type for IAsyncOperation<TResult> cannot be array

Question
-
If the template type for IAsyncOperation<TResult> is array, the app throws exceptions saying that the type cannot be recognizedWednesday, August 29, 2012 10:32 PM
Answers
-
Yes, Platform::Array can be passed across the ABI but it cannot be a generic parameter.
At the ABI, arrays get passed as 2 parameters (size and pointer to data). This unfortunately makes WinRT generics not allow arrays because generic instantiation requires that 1 formal generic parameter turn into 1 actual generic parameter.
A good workaround is to pass a boxed array as a parameter to IAsyncOperation i.e. IAsyncOperation<Platform::Object^>. This would only change the signature of your methods and not the implementation because Platform::Array already is a boxed array. You would still be ref-new-ing Platform::Arrays in your code.
Hope this helps,
Marian Luparu
Visual C++
- Marked as answer by Renjie Huang Thursday, August 30, 2012 6:45 PM
- Edited by Marian LuparuMicrosoft employee Sunday, September 2, 2012 10:43 PM Updated Platform::IBoxArray<T> to Platform::Object in the bolded text because IBoxArray is not a valid type in WinRT public surface (you can still use it however in internal/private types)
Thursday, August 30, 2012 5:49 PM
All replies
-
Yes. Take a look at the collection classes instead.
--Rob
- Marked as answer by Renjie Huang Thursday, August 30, 2012 4:50 PM
- Unmarked as answer by Renjie Huang Thursday, August 30, 2012 5:35 PM
Thursday, August 30, 2012 1:23 AMModerator -
Do you mean IAsyncOperation<TResult> can take a Window Runtime collection type as typename?
In my understanding, Platform::Array<T> also can be passed across ABI interface, right?
Thursday, August 30, 2012 5:35 PM -
Yes, Platform::Array can be passed across the ABI but it cannot be a generic parameter.
At the ABI, arrays get passed as 2 parameters (size and pointer to data). This unfortunately makes WinRT generics not allow arrays because generic instantiation requires that 1 formal generic parameter turn into 1 actual generic parameter.
A good workaround is to pass a boxed array as a parameter to IAsyncOperation i.e. IAsyncOperation<Platform::Object^>. This would only change the signature of your methods and not the implementation because Platform::Array already is a boxed array. You would still be ref-new-ing Platform::Arrays in your code.
Hope this helps,
Marian Luparu
Visual C++
- Marked as answer by Renjie Huang Thursday, August 30, 2012 6:45 PM
- Edited by Marian LuparuMicrosoft employee Sunday, September 2, 2012 10:43 PM Updated Platform::IBoxArray<T> to Platform::Object in the bolded text because IBoxArray is not a valid type in WinRT public surface (you can still use it however in internal/private types)
Thursday, August 30, 2012 5:49 PM -
Thanks for the detail information.Thursday, August 30, 2012 6:46 PM