2

I am creating composable WinRT component in C# and trying to add virtual method definition:

namespace FooComponent {
  [EnableComposition]
  public class Foo {
    public virtual void Bar() { }
  }
}

I've got an error from winmd export utility standing that "virtual method declaration is not allowed in managed WinRT components". But it is really easy to create such component in C++.

What is the reason to restict the ability to define custom virtual methods in a composable WinRT components, defined in managed code? What is the purpose of ability to enable implementation inheritance without custom virtual methods?

controlflow
  • 6,667
  • 1
  • 31
  • 55

1 Answers1

0

If you are attempting to build a Windows Runtime component that will be consumed by JavaScript, then you won't be able to do what you're attempting to. There are a set of rules to follow when doing so. Namely which is that your class must be marked as "sealed" which would prevent you from having any virtual methods anyways. Please see the documentation on MSDN that talks about creating Windows Runtime Components for JS - http://msdn.microsoft.com/en-us/library/windows/apps/br230301(v=vs.110).aspx

If you are not attempting to create a runtime component for JS, then you can change the output type of your library to "Class Library" to allow you to do what you are attempting.

Bob Delavan
  • 647
  • 5
  • 6
  • Please, read the question well first! I'm not building component, which will be consumable from JS. I'm building *composable* WinRT component. Composable WinRT components are hidden from web host by definition (like XAML controls). Changing output type to "Class Library"? Are you serious? – controlflow Feb 21 '12 at 09:57
  • Okay, misinterpreted your question. My bad. Can you tell me what build/release you are on (Developer Preview, Pre-Beta, Beta)? This functionality has changed and so this information is relevant. I can dig further on my end to see what's going on. – Bob Delavan Feb 21 '12 at 16:05
  • Developer Preview. It would be really good if it's just Dev Preview limitation. – controlflow Feb 21 '12 at 18:27