locked
C++/CX component "public enum class" Does not link correctly in C# Metro App.

    Question

  • Hi, i'm trying to wrap D3D11 calls in an API ive been developing.

    Ive made a C++/CX component library that i'm trying to use in C#.  This is simple and straightforward if the C++/CX component and C# project are in the SAME solution, everything will work fine...

    ...but if I create my C++/CX API component in its OWN solution then create a second C# Metro App solution and add my C++/CX component "project" to it and then have my C# Metro App reference the C++/CX component project I get runtime errors when trying to use public enums that were declared in C++.

    Here is the public enum class error that my C# app cant seem to link to.

    "Could not find Windows Runtime type 'Reign.Video.D3D11.FeatureLevels'."

    This is rly frustrating as I can't seem to get my C++/CX "API" stuff to link correctly in a C# app for TESTING.  How are you suppose to productively test an API made in C++ on metro??  You can't link a C++/CX component to a C# project unless there in the same solution and if you try to link the C++/CX project to the C# solution and link it from there you get runtime errors...

    Saturday, August 04, 2012 3:25 AM

Answers

All replies

  • Hello,

     

    Thanks for your feedback, I will involve more experts to investigate it.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 06, 2012 9:18 AM
  • I can't reproduce any problem here

    public enum class FeatureLevels
    {
    	One,
    	Two,
    	Three
    };

    I can add a reference to this windows runtime component to both C# and C++ projects and reference the enum class without errors.

    Can you give exact repro steps and errors?

    Monday, August 06, 2012 9:11 PM
    Moderator
  • Ok I figured out that when you use any other namespace other then that of the 'Project Name'... runtime linking(or something) does not work correctly. I'm going to send you a very simple demo for demonstration.

    Download Demo 'http://www.reign-studios.com/Share/MetroDemo.zip'

    Basically defining something like this in C++ will not link correctly at runtime in a C#(.NET) project.

    namespace Reign
    
    {namespace Video
    
    {namespace D3D11
    
    {
    
        public enum class FeatureLevels
        {
            D3D11_1,
            D3D11,
            D3D10_1,
            D3D10,
            ect...,
        };
    
    }
    
    }
    
    }



    • Edited by zezba9000 Tuesday, August 07, 2012 7:44 PM
    Tuesday, August 07, 2012 7:37 PM
  • My question was answered here: http://stackoverflow.com/questions/11805669/c-cx-component-public-enum-class-does-not-link-correctly-in-c-sharp-metro-ap/11853596#11853596

    "Windows Runtime requires that all types must be found in a namespace that matches the name of the containing .winmd file"

    I would recommend MS adding a compile time error for this situation, unless its technically unrealistic.

    • Marked as answer by zezba9000 Tuesday, August 07, 2012 9:25 PM
    Tuesday, August 07, 2012 9:25 PM