I built a WinRT(Windows phone 8.1) dll with Page.xaml and App.xaml files.
Next, I add reference to this winmd in wp8.1 application project.
And I get following error:
error APPX1706: The .winmd file 'project.winmd' contains type
'?A0x32772d97.project_XamlTypeInfo.XamlMetaDataProvider' outside its root namespace
'project'. Make sure that all public types appear under a common root namespace
that matches the output file name.
A WinMD library is basically a regular library (DLL) with some metadata information. These metadata information will allow it to be used from different languages. You can for example, create a WinMD library in C# and use it from a C++ or JS application.
Since the WinMD Library can be used by different languages, they are all conforming to the Windows Runtime rules.
Your specific problem is that one of the rules for the WinMD files states that all the classes must belong to the same root namespace.
It means that if you have the following code:
A.cs
namespace Foo { class A { ... } }
B.cs
namespace Foo.Sub { class B { ... } }
C.cs
namespace Bar { class C { ... } }
D.cs
namespace Bar.Sub { class D { ... } }
The WinMD linker will return the error you are seeing.
To solve it, you will have to declare all your classes in the same root namespace :
A.cs
namespace Foo { class A { ... } }
B.cs
namespace Foo.Sub { class B { ... } }
C.cs
namespace Foo { class C { ... } }
D.cs
namespace Foo.Sub { class D { ... } }
I've replaced all the "Bar" namespace by "Foo"
Related
I am getting error code C2512 which is no appropriate default constructor available. However it appears to me that everything should be working so I am a bit confused on how to get this to compile.
Here is the header file code:
namespace MyNamespace
{
ref class ForwadDeclaredClass;
public ref class MyClass
{
public:
MyClass();
// ...
private:
ForwadDeclaredClass^ fc;
}
}
Now in my cpp file I define the forwarded class and try to use it in the constructor for MyClass.
using namespace MyNamespace;
//...
public ref class ForwardDeclaredClass
{
public:
ForwardDeclaredClass()
{
}
}
MyClass::MyClass()
{
// Compiler complains with error code here
fc = gcnew ForwardDeclaredClass();
}
I know I have to be missing something simple but I am just not seeing it. Any help would be appreciated.
At first glance, it looks like your namespaces are off.
In the header file, you're declaring ForwardDeclaredClass and MyClass inside MyNamespace.
In the cpp file, you're using MyNamespace, but the code you're writing isn't inside the namespace.
It looks like you need to enclose most of the contents of the cpp file in a namespace MyNamespace { block.
I have a class C which is derived from a generic class D. I referenced the class C in a XAML file. When I build the app, I get the following error:
The tag 'C' does not exist in XML namespace 'clr-namespace:A.B'
I don't understand is this due to C is derived from a generic class. If I remove the base class, it does not give me any error.
How can I get rid of the error? The IInterfaceForE is injected via Unity, so the app works fine. But I can't get rid of the build error.
Code snippet:
namespace A.B
{
public class C : D<InterfaceForE>
{
public C()
{
}
}
}
// Reference in XAML
xmlns:myns="clr-namespace:A.B"
<myns:C x:Key="KeyForC"/>
// Code snippet after commenting out the base class.
// When I build with this code, there is no build error, but the app wont run.
namespace A.B
{
public class C //: D<InterfaceForE>
{
public C()
{
}
}
}
I had to remove the generic being used to make this work.
I have a Page that imports controls from a library like this:
<Page
x:Class="Foo.Bar.SomePage"
xmlns:myNamespace="using:Bar.Controls">
<myNamespace:SomeControl x:Name="someControl">
<!-- snip -->
</myNamespace:SomeControl>
</Page>
As you can see here, the page is declared in the ::Foo::Bar namespace, while SomeControl is declared in the ::Bar namespace. The problem I face is that Visual Studio generates this code:
namespace Bar {
namespace Controls {
ref class SomeControl;
}
}
namespace Foo
{
namespace Bar
{
partial ref class SomePage : /* ... */
{
/* ... */
private: Bar::SomeControl^ someControl;
};
}
}
The field definition Bar::SomeControl^ someControl tries to select ::Foo::Bar::SomeControl instead of ::Bar::SomeControl because Visual Studio doesn't fully-qualify it.
Is this by design (is there a way to phrase the using: URI in such a way that it will fully-qualify the name), or is this a bug? How can I work around that?
I think that I could convince people to make an exception to the namespace structure for this specific class, but it would be much simpler if there was an in-code solution for this.
For posterity, right now I'm using this kludge before #including the g.h file, but it's not super pretty:
namespace Foo
{
namespace Bar
{
typedef ::Bar::SomeControl SomeControl;
}
}
It introduces the control into the (incorrect) namespace so that it works even though the XAML code generator gets it wrong.
I have a javascript Windows Store application that I'm working on, and I needed to create a WinRT component for some processing. As soon as I add the reference to that component, I get a javascript error:
0x800a01bd - Javascript runtime error: Object doesn't support this action.
This occurs on a line w/ the following:
engine = new MyApp.Engine();
Which is defined:
WinJS.Namespace.define("MyApp", {
Engine: WinJS.Class.define(function() {
//constructor stuff
//other stuff snipped for brevity
}
});
I'm not even accessing any code in my custom component, simply adding the reference causes it to break. Anyone run into this? Googling/Binging has been no help.
I found the answer.
So in my Javascript code, I had the declaration for a namespace.
In my WinRT C# component, I was using the same namespace. That namespace apparently stomps out my JS namespace declartion. I changed my WinRT component from this:
namespace MyApp
{
public sealed class SomeClass
{
}
}
to:
namespace MyAppUtils
{
public sealed class SomeClass
{
}
}
And now everything is good..so, Lesson: If you're using JS and a custom WinRT component, you (apparently) can't use the same namespace in both.
I want to write Tomboy add-on using IronPython and I'm stuck and very beginning -- I need to provide C#'s namespace.
I mean, here's howto in writing Tomboy add-on's http://live.gnome.org/Tomboy/HowToCreateAddins
Let's start with creating the plugin
file called InsertDateTime.cs with the
following content:
using Tomboy;
namespace Tomboy.InsertDateTime
{
public class InsertDateTimeAddin : NoteAddin
{
public override void Initialize ()
{
}
public override void Shutdown ()
{
}
public override void OnNoteOpened ()
{
}
}
}
Can I do that with IronPython? Thank you.
From Python you can import the clr module and then call clr.AddReference('AssemblyName') where assembly name is a partial or full assembly name - maybe in your case it's Tomboy, it's whatever you'd compile against with C#. Then you can do "import Tomboy" or "from Tomboy import NoteAddin".
If you're hosting IronPython via the hosting APIs you can instead do scriptRuntime.LoadAssembly(typeof(NoetAddin).Assembly); so that you don't have to do it in Python. That can be particularly useful to avoid various loader context issues depending on how the assembly gets loaded.