locked
Error when trying to consume a C++ WinRT component from c#: "Typename or namespace was not found in metadata file"

    Question

  • RssReader.h

    public ref class RssReader sealed
    {
    public:
        static Windows::Foundation::IAsyncOperation<RssChannel^>^ ReadRssFeed(Windows::Foundation::Uri^ uri);
    };

    RssReader.cpp

    RssChannel^ ImportRssFile(String^ filename);

    IAsyncOperation<RssChannel^>^ RssReader::ReadRssFeed(Uri^ uri) { return create_async( [uri]() -> task<RssChannel^> { task<void> start; return start.then([] () -> IAsyncOperation<StorageFile^>^ { StorageFolder^ l_TempFolder = ApplicationData::Current->TemporaryFolder; return l_TempFolder->CreateFileAsync("feed.xml", CreationCollisionOption::GenerateUniqueName); }).then( [uri] (StorageFile^ a_file) { BackgroundDownloader l_bd; auto l_DownloadOperation = l_bd.CreateDownload(uri, a_file); return l_DownloadOperation->StartAsync(); }).then( [] (DownloadOperation^ download) -> IAsyncOperation<RssChannel^>^ { String^ filename = download->ResultFile->Path; return create_async([filename] () { return ImportRssFile(filename); } ); }); }); }

    BlankPage.xaml.cs

    private async void Btn_Test_Click(object sender, RoutedEventArgs e)
    {
        string uristr = "http://cyber.law.harvard.edu/rss/examples/rss2sample.xml";
        Uri uri = new Uri(uristr);
    
        RssChannel channel = await RssReader.ReadRssFeed(uri);
    }

    When "Btn_Test" is clicked, before Btn_Test_click() is even allowed to run (as shown by placing a debug point on it), the system experiences the above error. It is breaking in "App.g.i.cs" on the unhanded exception handler. The HRESULT is 0x8000000F. 

    Intellitrace is saying: "Failed to collect details. Failed to generate short description"

    Any help with this will be greatly appreciated. 

    Saturday, March 10, 2012 1:07 AM

Answers

  • Yes I forgot to mention, commenting out the RssChannel line did make the error go away.

    I found out what was wrong. Within my C++ Runtime component I had changed the name of the namespace I was using such that it was different from the name of the library project.

    The fact that this resulted in runtime error instead of at compile time error, I consider to be a bug. There should probably be a compile time check that ensures that any public ref classes are contained within the namespace or sub namespace of a C++\CX library project.

    • Marked as answer by Chris Gunn Saturday, March 10, 2012 11:38 PM
    Saturday, March 10, 2012 11:36 PM

All replies

  • Hi Chris,

    Try commenting out the RssChannel line to see if that get's you past the error. If so, check the project settings for the C# project Build settings as well as the C++ project platform configuration setting. The Media capture using webcam sample has an example of a C# project referencing a C++ project you can refer to as an example.

    You could also create a new button with a separate event handler which simple updates the button Content to make sure the basics are working.

    Let us know what you find.


    David Lamb


    Saturday, March 10, 2012 3:07 AM
    Moderator
  • Yes I forgot to mention, commenting out the RssChannel line did make the error go away.

    I found out what was wrong. Within my C++ Runtime component I had changed the name of the namespace I was using such that it was different from the name of the library project.

    The fact that this resulted in runtime error instead of at compile time error, I consider to be a bug. There should probably be a compile time check that ensures that any public ref classes are contained within the namespace or sub namespace of a C++\CX library project.

    • Marked as answer by Chris Gunn Saturday, March 10, 2012 11:38 PM
    Saturday, March 10, 2012 11:36 PM