Referencing a custom WinRT component breaks javascript class? - windows-8

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.

Related

Use a #typeparam as component in Blazor

Is it possible to use a #typeparam as Component?
More explicitly, do something like the following MyComponent.razor:
#typeparam TComponent
<TComponent />
Of course, there would also be a MyComponent.razor.cs file whose content would be:
public partial MyComponent<TComponent> : ComponentBase where TComponent : ComponentBase
so that the compiler would know that <TComponent /> is meaningful.
I cannot find any documentation about this in Microsoft docs.
When I try it seems to compile, but display the following warning:
warning RZ10012: Found markup element with unexpected name 'TComponent'. If this is intended to be a component, add a #using directive for its namespace
However it is only a warning and not an error. It does't show anything in the browser though.
I am using ASP.NET 5.
Thanks
Not quite sure what you are trying to do but you can write what I believe you are trying to achieve as a component class like this:
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
namespace BlazorTest.Pages
{
public class ComponentRenderer<TComponent> : ComponentBase where TComponent : IComponent
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenComponent<TComponent>(1);
builder.CloseComponent();
}
}
}
So in Index.razor you can do something like the following to render a component of type FetchData:
....
<ComponentRenderer TComponent="FetchData"></ComponentRenderer>
....
If I'm wide of the mark post a little more information.

What is `static inject...`

I found this line of code in Aurelia Dialog
static inject = [DialogService];
This is the full class:
import {Prompt} from './prompt';
import {DialogService} from '../dialog-service';
export class CommonDialogs {
static inject = [DialogService];
constructor(dialogService){
this.dialogService = dialogService;
}
prompt(question){
return this.dialogService.open({viewModel:Prompt, model:question});
};
}
What is the static inject doing? I get that it is injecting the dialog service into the constructor. But why do it this way instead of the usual inject?
As the blog post you linked to mentions, static inject was the original way to do dependency injection. Once Babel started supporting decorators, we implemented the inject decorator to make Aurelia code look a little nicer. Under the covers, it simply adds the inject property to the class at runtime (https://github.com/aurelia/dependency-injection/blob/master/src/decorators.js#L13).

Disambiguating namespaces in generated XAML code

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.

Provide C#'s namespace from IronPython

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.

Mef, passing parameters to a module

I'm studying MEF and I'm not able to resolve a problem.
I have a main application, called MainMEF, and a simple module, called SimpleModule. This one consists of a single UserControl which is loaded dynamically.
When MainMEF starts up, I would be able to pass to the module a reference to main application contained into MainMEF.
How could I fix this?
Lots of questions regarding this already.
You could pass it after initialisation using a property:
How do I populate a MEF plugin with data that is not hard coded into the assembly?
Or use MEF constructor parameters:
MEF Constructor Parameters with Multiple Constructors
The export looks something like this:
[Export(typeof(ITest))]
class Test : ITest
{
void Test()
{ }
[ImportingConstructor] //<- This is the key bit here
void Test(object parameter)
{ }
}
Then when composing your catalog do this:
catalog.ComposeExportedValue( /* parameter here */);
catalog.ComposeParts(this);