skyflashde
Topic Author
Posts: 5
Joined: 17 May 2019, 16:35

MainWindow.xaml not loading using Application Framework on .NET Core

17 May 2019, 16:47

Hi, I am trying to get a console .NET Core app working that starts up Noesis.

I followed your samples and this post: viewtopic.php?f=3&t=1668

I got the following files now:

Program.cs:
namespace Dashboard
{
    class Program
    {
        static App app;

        public static void Main(string[] args)
        {
            app = new App() { Uri = "App.xaml", StartupUri = "MainWindow.xaml" };
            app.Run();
        }
    }
}
App.xaml.cs:
using NoesisApp;

namespace Dashboard
{
    public partial class App : Application
    {
        public App()
        {
        }

        protected override Display CreateDisplay()
        {
            return new Win32Display();
        }

        protected override RenderContext CreateRenderContext()
        {
            return new RenderContextD3D11();
        }
    }
}
MainWindow.xaml.cs:
namespace Dashboard
{
    public class MainWindow : NoesisApp.Window
    {
        public MainWindow()
        {
        }
}
My problem is that the MainWindow constructor never gets hits. A window opens, but the screen is completely black.

The last thing that works is the app.Run(); after that my app is dead. No more breakpoints get hit.

All my XAML are on embedded now.
The App.xaml and the MainWindow.xaml are the empty stubs from the sample, the namespaces and class names have been checked like 100 times.
I am using the newest NuGets, no problems with dependencies as far as I can tell.

Does anyone have any clue why this could be happening?

Thank you!

Tags:
 
dstroup
Posts: 2
Joined: 27 Feb 2019, 21:18

Re: MainWindow.xaml not loading using Application Framework on .NET Core

17 May 2019, 20:33

Your MainWindow.xaml and MainWindow.xaml.cs files probably aren't being linked up properly at build time (and the same is likely true for App.xaml/App.xaml.cs depending on how you created them).

xaml.cs files are usually partial classes to allow combining them with the xaml, so your MainWindows.xaml.cs should have
public partial class MainWindow : NoesisApp.Window
instead of
public class MainWindow : NoesisApp.Window

You'll also need to specify that the xaml.cs files are dependent on the xaml files in your project file, if they aren't already. If you use Visual Studio, this is normally handled for you when adding new WPF classes. .NET Core doesn't do that since it doesn't support WPF yet. You can do this by adding the following to your project file:
<ItemGroup>
    <!-- You may not need this first line -->
    <Compile Include="**\*.cs" Exclude="obj\**" />
    <Compile Update="**\*.xaml.cs">
        <DependentUpon>%(Filename)</DependentUpon>      
        <SubType>Code</SubType>
    </Compile>
  </ItemGroup>
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: MainWindow.xaml not loading using Application Framework on .NET Core

17 May 2019, 21:51

Hi skyflashde,

As I can't see the xamls my guess is that you don't have the x:Class in the MainWindow root, so it is creating a default Window instead, could that be the problem?
I created an empty .NET Core console project myself that works so you can compare it with your own. Please take a look at the attached zip and let me know.

Hope this helps.
Attachments
ConsoleApp1.zip
(2.94 KiB) Downloaded 29 times
 
wyvern010
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: MainWindow.xaml not loading using Application Framework on .NET Core

19 May 2019, 18:18

have you tried setting all .xaml files to: Embeded Resource inside the file properties tab?
That was the thingy that made it work for me...


Cheers!
 
skyflashde
Topic Author
Posts: 5
Joined: 17 May 2019, 16:35

Re: MainWindow.xaml not loading using Application Framework on .NET Core

20 May 2019, 08:38

Good morning....

I have implemented all of your suggestions and it is still not working.

The sample project is working, however.

I have tried to modify my project according to the sample, but so far that doesn't work. The only difference between my code (that isnt working) and the sample (which is working) are now the additional dependencies (which I need), the folder path and the namespace name.

So next I will try to put my code into the working sample until it stops working.

No clue. Really.

Thanks though. ;)
 
skyflashde
Topic Author
Posts: 5
Joined: 17 May 2019, 16:35

Re: MainWindow.xaml not loading using Application Framework on .NET Core

20 May 2019, 08:52

Ok, I found the problem.

It is the namespace name.

If I take the sample application and change the namespace from ConsoleApp1 to ConsoleApp2 it stops working.

Anyone have a clue why that could be happening? :)

This is my problem, just that its not the solution, its the .csproj filename:

https://github.com/aspnet/AspNetCore/issues/5524

Solution to my problem:

Insert this into .csproj -> <RootNamespace>MyNamespace</RootNamespace>

If it is missing, all the generated code is compiled into some namespace that is constructed by the folder structure or whatever and the Application framework doesn't work.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: MainWindow.xaml not loading using Application Framework on .NET Core

21 May 2019, 11:54

After some investigation I found that Visual Studio uses <RootNamespace> project property to generate the name of the Embedded Resources, and unfortunately that value is not available during runtime because it is a Visual Studio thing. So if you have "ConsoleApp1" as RootNamespace, then manifest resource names will be in the form "ConsoleApp1.Folder1.Folder2.File.ext".

Our default embedded resource providers use the current Application object namespace to build the manifest resource name and perform the resource lookup, so in order to work RootNamespace project property must match the Application namespace.

Who is online

Users browsing this forum: No registered users and 1 guest