WP8: can't consume a native component

3

Windows Phone 8 C# project (MyApp), migrated from WP7.1. I've added a native Windows Runtime component library (AppLib) to the solution, created a reference. There's a public sealed ref class (MyClass) in it. There's a reference to it in the C# code (in OnLoaded of the main XAML page). The whole thing compiles - meaning the metadata of the component is being generated.

When I'm trying to run, the project fails with the exception or type TypeLoadException with the following message:

Typename or Namespace was not found in metadata file. (Exception from HRESULT: 0x8000000F)

Both AppLib.DLL and AppLib.winmd can be found in the XAP. The winmd contains the information about the type, and in the right namespace, too. What else should I check?

At exception time, the AppLib.dll is not listed in the modules window of the debugger. It's as if the DLL loading fails for some reason.

I've tried with brand new class in an arbitrary namespace - same problem. Looks like the problem is on the DLL level, not on class level.

windows-runtime
windows-phone-8
asked on Stack Overflow Nov 5, 2012 by Seva Alekseyev • edited Nov 5, 2012 by Seva Alekseyev

1 Answer

4

The name of the WinMD file must be a prefix of the name of the namespace in which any public and activatable types are declared. For example, if your WinMD is named AppLib.winmd, your MyClass type must be defined in namespace AppLib or some other namespace nested within that namespace, for example AppLib::Something.

It must also be declared in the "best matching" WinMD, so if your type is named A.B.MyClass and you have both A.winmd and A.B.winmd in your package, the type must be defined in A.B.winmd.

The Windows Runtime uses the name of the type to determine which WinMD file defines the type. See also my answer to "XAML cannot find reference in local namespace."

answered on Stack Overflow Nov 5, 2012 by James McNellis • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0