locked
Accessing C# WinRT Component from C++ Win RT component

    Question

  • Hi I have an Application that accesses a C++ WinRT component which in turn accesses C# WinRt component. The call to the C++ component goes through. But when the C++ component tries to create a new object from the C# namespace, an exception is thrown with the error message "ClassFactory cannot supply requested class". Any suggestions?

    Saturday, January 21, 2012 1:23 AM

Answers

  • Nice find! This appears to be a Developer Preview bug. Everything worked fine until I added the constructors you were implementing into the equation. Please submit a VS bug here for us to track please:

    http://connect.microsoft.com/VisualStudio

     

    Let me know if you have any trouble entering the bug please.

     

    Thanks,

    -David

    Monday, January 30, 2012 5:59 PM
    Moderator

All replies

  • In general this works assuming your C# component is not compiled to a platform setting incompatible with your C++ component.

     

    Can you describe the steps you used to create this configuration, specifically how you created the references between the components?

    Are all the projects in the same solution?

     

    It would also be helpful to see your C# class declaration as well as the C++ client code failing to instantiate the component.

     

    Thanks,

    -David


    Tuesday, January 24, 2012 7:30 PM
    Moderator
  • Yes all the projects are in the same solution. I simply created a C++ app and then added a C++ Winrt component project to it and then a C# WinRT project. I created a reference in the C++ app for the C++ WinRT and in the C# WinRT. I have tried this out in various orders, just for the heck. But it didnt work.

    I finally resorted to create a test app with most of the unmodified code from Visual Studio.

    C# class:

    namespace ClassLibrary1
    {
        public sealed class Class1
        {
            private int var;
            public Class1()
            {
                var = 0;
            }

            public Class1(int x)
            {
                var = x;
            }

            public int getVar()
            {
                return var;
            }

        }
    }

    C++ WinRT calling C# WinRT:

    int WinRTComponent::Method(int i)
    {
        try {
        auto cl = ref new ClassLibrary1::Class1(i);
        i = cl->getVar();
        return i;
        }
        catch (Exception ^e)
        {
            auto msg = e->Message;
        }
        return 0;
    }

     

    C++ client code:

    MainPage::MainPage()
    {
        InitializeComponent();
        auto wr = ref new WinRTComponentDll1::WinRTComponent;
        wr->Method(2);
    }

     

     

    Wednesday, January 25, 2012 7:59 AM
  • Nice find! This appears to be a Developer Preview bug. Everything worked fine until I added the constructors you were implementing into the equation. Please submit a VS bug here for us to track please:

    http://connect.microsoft.com/VisualStudio

     

    Let me know if you have any trouble entering the bug please.

     

    Thanks,

    -David

    Monday, January 30, 2012 5:59 PM
    Moderator
  • Thanks. I have submitted the bug.
    Tuesday, February 07, 2012 2:20 AM