[GH-ISSUE #207] Doesn't work properly with .NET Framework/Mono #131

Closed
opened 2026-05-05 11:06:16 -06:00 by gitea-mirror · 10 comments
Owner

Originally created by @FieryRider on GitHub (May 31, 2020).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/207

This is not the same issue as #76 though it's probably related.

  • It doesn't want to run in projects using the old packages.config. When ran from those type of projects it results in exception:
    at Qml.Net.Internal.Interop..cctor()
    --- End of inner exception stack trace ---
    at Qml.Net.Internal.Interop.get_QQuickStyle()
    at Qml.Net.QQuickStyle.SetStyle(String style)
    at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 17
    

If converted to PackageReference there is no longer exception.

  • When run with PackageReference everything seems to work fine (if we ignore the following error QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)), the app loads, the custom (C#) components load until you try to access something in a custom (C#) component. Then it results in the following exception:
    at method(NetReference , NetVariantList , NetVariant , Task& )
    at Qml.Net.Internal.DefaultCallbacks.InvokeMethod(IntPtr m, IntPtr t, IntPtr p, IntPtr r)
    at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 17
    QQmlComponent: Component destroyed while completion pending
    
    

This is my code (if you remove mainController.print() it works fine):
Program.cs

using Qml.Net;
using Qml.Net.Runtimes;

namespace QmlTestNF {
    class Program {
        static int Main(string[] args) {
            RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();
            QQuickStyle.SetStyle("Material");
            using (var application = new QGuiApplication()) {
                using (var qmlEngine = new QQmlApplicationEngine()) {
                    Qml.Net.Qml.RegisterType<MainController>("Extends");
                    qmlEngine.Load("Main.qml");
                    
                    return application.Exec();
                }
            }
        }
    }
}

MainController.cs

using System;
namespace QmlTestNF {
    class MainController {
        public void Print() {
            Console.WriteLine("Something");
        }
    }
}

Main.qml

import QtQuick 2.12
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import Extends 1.0

ApplicationWindow {
    id: window
    width: 1366
    height: 768
    visible: true
    title: "DMTViewer"

    Material.theme: Material.Dark
    Material.primary: Material.Grey
    Material.accent: Material.Green

    MainController {
        id: mainController
        Component.onCompleted: {
            console.log("loaded")
            mainController.print()
        }
    }    
}
Originally created by @FieryRider on GitHub (May 31, 2020). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/207 This is not the same issue as #76 though it's probably related. - It doesn't want to run in projects using the old `packages.config`. When ran from those type of projects it results in exception: ```Unhandled Exception: System.TypeInitializationException: The type initializer for 'Qml.Net.Internal.Interop' threw an exception. ---> System.Exception: Unable to find the native Qml.Net library. Try calling "RuntimeManager.DiscoverOrDownloadSuitableQtRuntime();" in Program.Main() at Qml.Net.Internal.Interop..cctor() --- End of inner exception stack trace --- at Qml.Net.Internal.Interop.get_QQuickStyle() at Qml.Net.QQuickStyle.SetStyle(String style) at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 17 If converted to PackageReference there is no longer exception. - When run with PackageReference everything seems to work fine (if we ignore the following error `QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)`), the app loads, the custom (C#) components load until you try to access something in a custom (C#) component. Then it results in the following exception: ```Unhandled Exception: System.TypeAccessException: Attempt by method 'DynamicClass.method(Qml.Net.Internal.Types.NetReference, Qml.Net.Internal.Qml.NetVariantList, Qml.Net.Internal.Qml.NetVariant, System.Threading.Tasks.Task ByRef)' to access type 'Qml.Net.Internal.Types.NetReference' failed. at method(NetReference , NetVariantList , NetVariant , Task& ) at Qml.Net.Internal.DefaultCallbacks.InvokeMethod(IntPtr m, IntPtr t, IntPtr p, IntPtr r) at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 17 QQmlComponent: Component destroyed while completion pending This is my code (if you remove `mainController.print()` it works fine): Program.cs ```c# using Qml.Net; using Qml.Net.Runtimes; namespace QmlTestNF { class Program { static int Main(string[] args) { RuntimeManager.DiscoverOrDownloadSuitableQtRuntime(); QQuickStyle.SetStyle("Material"); using (var application = new QGuiApplication()) { using (var qmlEngine = new QQmlApplicationEngine()) { Qml.Net.Qml.RegisterType<MainController>("Extends"); qmlEngine.Load("Main.qml"); return application.Exec(); } } } } } ``` MainController.cs ```c# using System; namespace QmlTestNF { class MainController { public void Print() { Console.WriteLine("Something"); } } } ``` Main.qml ```qml import QtQuick 2.12 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.12 import QtQuick.Controls.Material 2.12 import Extends 1.0 ApplicationWindow { id: window width: 1366 height: 768 visible: true title: "DMTViewer" Material.theme: Material.Dark Material.primary: Material.Grey Material.accent: Material.Green MainController { id: mainController Component.onCompleted: { console.log("loaded") mainController.print() } } } ```
gitea-mirror 2026-05-05 11:06:16 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

It works for me on Linux (not helpful, I know).

image

Let me try on Windows in a bit.

<!-- gh-comment-id:636434040 --> @pauldotknopf commented on GitHub (May 31, 2020): It works for me on Linux (not helpful, I know). ![image](https://user-images.githubusercontent.com/523150/83346893-8c6b9b80-a2ee-11ea-8a44-08fb1103ebdb.png) Let me try on Windows in a bit.
Author
Owner

@FieryRider commented on GitHub (May 31, 2020):

On Linux it runs under .Net Core doesn't it? I don't have problems with .Net Core on Linux nor on Windows. But .Net Framework is problematic.

<!-- gh-comment-id:636434196 --> @FieryRider commented on GitHub (May 31, 2020): On Linux it runs under `.Net Core` doesn't it? I don't have problems with `.Net Core` on Linux nor on Windows. But `.Net Framework` is problematic.
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

What does your csproj look like? Share a repro repo?

<!-- gh-comment-id:636434455 --> @pauldotknopf commented on GitHub (May 31, 2020): What does your csproj look like? Share a repro repo?
Author
Owner

@FieryRider commented on GitHub (May 31, 2020):

https://github.com/FieryRider/TestRepo1

<!-- gh-comment-id:636434657 --> @FieryRider commented on GitHub (May 31, 2020): https://github.com/FieryRider/TestRepo1
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

Ok, it looks like it's loading the native libs correctly.

I'd like to see the actual exception. Is it a .NET exception? Or a native segfault? My Windows machine with me right now, it would help a lot of you could compile QmlNet yourself (at 0.10.1), so that I can get a full stacktrace.

<!-- gh-comment-id:636435598 --> @pauldotknopf commented on GitHub (May 31, 2020): Ok, it looks like it's loading the native libs correctly. I'd like to see the actual exception. Is it a .NET exception? Or a native segfault? My Windows machine with me right now, it would help a lot of you could compile QmlNet yourself (at 0.10.1), so that I can get a full stacktrace.
Author
Owner

@FieryRider commented on GitHub (May 31, 2020):

Will you compile it from the code of the repo I gave or should I compile QmlNet and give you the info?
It's .Net exception

Attempt by method 'DynamicClass.method(Qml.Net.Internal.Types.NetReference, Qml.Net.Internal.Qml.NetVariantList, Qml.Net.Internal.Qml.NetVariant, System.Threading.Tasks.Task ByRef)' to access type 'Qml.Net.Internal.Types.NetReference' failed.
   at method(NetReference , NetVariantList , NetVariant , Task& )
   at Qml.Net.Internal.DefaultCallbacks.InvokeMethod(IntPtr m, IntPtr t, IntPtr p, IntPtr r)
   at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 20
<!-- gh-comment-id:636435925 --> @FieryRider commented on GitHub (May 31, 2020): Will you compile it from the code of the repo I gave or should I compile QmlNet and give you the info? It's .Net exception ``` Attempt by method 'DynamicClass.method(Qml.Net.Internal.Types.NetReference, Qml.Net.Internal.Qml.NetVariantList, Qml.Net.Internal.Qml.NetVariant, System.Threading.Tasks.Task ByRef)' to access type 'Qml.Net.Internal.Types.NetReference' failed. at method(NetReference , NetVariantList , NetVariant , Task& ) at Qml.Net.Internal.DefaultCallbacks.InvokeMethod(IntPtr m, IntPtr t, IntPtr p, IntPtr r) at QmlTestNF.Program.Main(String[] args) in D:\@UserFolder@\Documents\code\C#\QmlTestNF\QmlTestNF\Program.cs:line 20 ```
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

Erggh, it looks like it's the dynamic IL that's being generated doesn't plan nice with .NET Framework.

<!-- gh-comment-id:636439004 --> @pauldotknopf commented on GitHub (May 31, 2020): Erggh, it looks like it's the dynamic IL that's being generated doesn't plan nice with .NET Framework.
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

System.TypeAccessException
  HResult=0x80131543
  Message=Attempt by method 'DynamicClass.method(Qml.Net.Internal.Types.NetReference, Qml.Net.Internal.Qml.NetVariantList, Qml.Net.Internal.Qml.NetVariant, System.Threading.Tasks.Task ByRef)' to access type 'Qml.Net.Internal.Types.NetReference' failed.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
<!-- gh-comment-id:636439079 --> @pauldotknopf commented on GitHub (May 31, 2020): ``` System.TypeAccessException HResult=0x80131543 Message=Attempt by method 'DynamicClass.method(Qml.Net.Internal.Types.NetReference, Qml.Net.Internal.Qml.NetVariantList, Qml.Net.Internal.Qml.NetVariant, System.Threading.Tasks.Task ByRef)' to access type 'Qml.Net.Internal.Types.NetReference' failed. Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace> ```
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

I'm pushing an alpha nuget package soon, I'll ping you when it is up.

<!-- gh-comment-id:636442849 --> @pauldotknopf commented on GitHub (May 31, 2020): I'm pushing an alpha nuget package soon, I'll ping you when it is up.
Author
Owner

@pauldotknopf commented on GitHub (May 31, 2020):

Pushed.

<!-- gh-comment-id:636445513 --> @pauldotknopf commented on GitHub (May 31, 2020): [Pushed](https://www.nuget.org/packages/Qml.Net/0.11.0-alpha.78).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#131
No description provided.