{"id":49562956,"url":"https://github.com/player-alex/net-host","last_synced_at":"2026-05-03T10:46:47.642Z","repository":{"id":318619849,"uuid":"1072044292","full_name":"player-alex/net-host","owner":"player-alex","description":"A lightweight native C++ host for running .NET assemblies without modification. Supports WPF applications, console apps, and any .NET DLL with a Main method via simple JSON configuration.","archived":false,"fork":false,"pushed_at":"2025-10-10T06:20:58.000Z","size":156,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-03T10:46:46.564Z","etag":null,"topics":["application-launcher","assembly-loader","cpp","cpp20","csharp","dll-host","dotnet","dotnet-core","dotnet-hosting","hostfxr","interop","native-host","native-interop","windows","wpf"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/player-alex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-08T07:21:56.000Z","updated_at":"2026-04-20T15:44:02.000Z","dependencies_parsed_at":"2025-10-08T09:20:17.478Z","dependency_job_id":"fcaaa0eb-274e-4159-94a7-d05a04dd1ed7","html_url":"https://github.com/player-alex/net-host","commit_stats":null,"previous_names":["player-alex/net-host"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/player-alex/net-host","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/player-alex%2Fnet-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/player-alex%2Fnet-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/player-alex%2Fnet-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/player-alex%2Fnet-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/player-alex","download_url":"https://codeload.github.com/player-alex/net-host/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/player-alex%2Fnet-host/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32566444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["application-launcher","assembly-loader","cpp","cpp20","csharp","dll-host","dotnet","dotnet-core","dotnet-hosting","hostfxr","interop","native-host","native-interop","windows","wpf"],"created_at":"2026-05-03T10:46:47.110Z","updated_at":"2026-05-03T10:46:47.637Z","avatar_url":"https://github.com/player-alex.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# 🚀 .NET Generic Host\n\n![Platform](https://img.shields.io/badge/platform-Windows-0078D6?logo=windows\u0026logoColor=white)\n![.NET](https://img.shields.io/badge/.NET-8.0-512BD4?logo=.net\u0026logoColor=white)\n![C++](https://img.shields.io/badge/C++-20-00599C?logo=cplusplus\u0026logoColor=white)\n![License](https://img.shields.io/badge/license-MIT-blue.svg)\n\n**A lightweight native C++ host for running .NET assemblies without modification. Perfect for hosting WPF applications, console apps, or any .NET DLL with a `Main` method.** 🎯\n\n\u003c/div\u003e\n\n---\n\n## ✨ Features\n\n- 🔄 **Zero Assembly Modification** - Run any .NET DLL without changing source code\n- 🎨 **WPF Support** - Full support for WPF applications with proper resource loading\n- 🧵 **STA Threading** - Automatic COM initialization for UI applications\n- ⚙️ **JSON Configuration** - Simple configuration via `net-host.json`\n- 📦 **Entry Assembly Support** - Properly sets entry assembly for resource loading\n- 💬 **Command-line Arguments** - Pass arguments to the hosted application\n\n## 🎯 Use Cases\n\n- 🖥️ Host WPF applications from native C++ code\n- 📚 Run .NET DLLs as standalone applications\n- 🚀 Create custom .NET application launchers\n- 🔗 Bridge native and managed code seamlessly\n\n## 🛠️ Building\n\n### Prerequisites\n\n- 🔧 **Visual Studio 2022** or later\n- 🔷 **.NET 8.0 SDK** - [Download](https://dotnet.microsoft.com/download/dotnet/8.0)\n- ⚡ **C++20 support**\n\n### Build Steps\n\n1. Open `net-host.sln` in Visual Studio\n2. Build the solution (Release/x64 recommended)\n3. Output: `net-host.exe` in `x64/Release` or `x64/Debug`\n\n## 📖 Usage\n\n### 1️⃣ Create Configuration File\n\nCreate `net-host.json` in the same directory as `net-host.exe`:\n\n```json\n{\n  \"assemblyPath\": \"YourApp.dll\",\n  \"typeName\": \"YourNamespace.Program\",\n  \"methodName\": \"Main\",\n  \"arguments\": []\n}\n```\n\n### 2️⃣ Prepare Your .NET Assembly\n\nEnsure your .NET application has a `public static void Main()` or `public static void Main(string[] args)` method:\n\n```csharp\nnamespace YourNamespace\n{\n    public class Program\n    {\n        public static void Main(string[] args)\n        {\n            // Your application code\n            var app = new App();\n            app.Run();\n        }\n    }\n}\n```\n\n### 3️⃣ Deploy Files\n\nPlace in the same directory:\n- `net-host.exe`\n- `net-host.json`\n- `nethost.dll` (from .NET SDK)\n- `YourApp.dll` and all its dependencies\n- `YourApp.runtimeconfig.json`\n\n### 4️⃣ Run\n\n```bash\nnet-host.exe\n```\n\n## ⚙️ Configuration Reference\n\n| Field | Type | Required | Description |\n|-------|------|----------|-------------|\n| `assemblyPath` | string | ✅ Yes | Path to the .NET DLL (relative or absolute) |\n| `typeName` | string | ✅ Yes | Fully qualified type name (e.g., `Namespace.Class`) |\n| `methodName` | string | ❌ No | Entry method name (default: `Main`) |\n| `arguments` | array | ❌ No | Command-line arguments to pass to Main |\n\n### Example with Arguments\n\n```json\n{\n  \"assemblyPath\": \"MyApp.dll\",\n  \"typeName\": \"MyApp.Program\",\n  \"methodName\": \"Main\",\n  \"arguments\": [\n    \"--config\", \"production.json\",\n    \"--verbose\"\n  ]\n}\n```\n\n## 🏗️ How It Works\n\n1. **Configuration Loading** - Reads `net-host.json` to get assembly information\n2. **hostfxr Initialization** - Loads .NET hosting library (`hostfxr.dll`)\n3. **Runtime Initialization** - Initializes .NET runtime using `hostfxr_initialize_for_dotnet_command_line`\n4. **COM/STA Setup** - Initializes COM in STA mode for WPF support\n5. **Application Execution** - Calls `hostfxr_run_app` to execute the Main method\n6. **Entry Assembly Setup** - Automatically sets entry assembly for resource loading\n\n## 🎨 WPF Applications\n\nFor WPF applications, the host automatically:\n- ✅ Initializes COM in STA (Single-Threaded Apartment) mode\n- ✅ Sets up entry assembly for `pack://` URI resource loading\n- ✅ Handles `Application.ResourceAssembly` resolution\n- ✅ Supports XAML resource loading\n\nNo modifications needed to your WPF application!\n\n## 🐛 Troubleshooting\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e❌ Assembly Not Found\u003c/b\u003e\u003c/summary\u003e\n\n- ✅ Ensure the DLL path in `net-host.json` is correct\n- ✅ Check that all dependency DLLs are in the same directory\n- ✅ Verify the assembly path is relative to `net-host.exe` location\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e⚠️ Runtime Initialization Failed\u003c/b\u003e\u003c/summary\u003e\n\n- ✅ Verify .NET 8.0 Runtime is installed\n- ✅ Check that `runtimeconfig.json` exists next to the DLL\n- ✅ Ensure `rollForward` policy in `runtimeconfig.json` allows runtime version\n- ✅ Verify `nethost.dll` is present in the same directory\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e🎨 WPF Resource Loading Issues\u003c/b\u003e\u003c/summary\u003e\n\n- ✅ Verify all resource DLLs are present\n- ✅ Check that XAML resources are embedded correctly\n- ✅ Ensure `Build Action` for resources is set to `Resource`\n- ✅ Verify pack URIs are correct in your XAML files\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e🔧 COM Initialization Failed\u003c/b\u003e\u003c/summary\u003e\n\n- ✅ Close other applications that may conflict\n- ✅ Run as administrator if necessary\n- ✅ Check if COM is already initialized in a different mode\n\n\u003c/details\u003e\n\n## 🔧 Technical Details\n\n### Architecture\n\n```\nnet-host.exe (Native C++)\n    ↓ hostfxr API\n.NET Runtime\n    ↓ load_assembly_and_get_function_pointer\nYourApp.dll\n    ↓ Main() execution\nWPF Application / Console App\n```\n\n### Key APIs Used\n\n| API | Purpose |\n|-----|---------|\n| `hostfxr_initialize_for_dotnet_command_line` | Simulates `dotnet YourApp.dll` |\n| `hostfxr_run_app` | Executes the application's Main method |\n| `CoInitializeEx` | Initializes COM for UI threading |\n\n## 📦 Example Projects\n\n### Console Application\n\n```json\n{\n  \"assemblyPath\": \"ConsoleApp.dll\",\n  \"typeName\": \"ConsoleApp.Program\",\n  \"methodName\": \"Main\",\n  \"arguments\": [\"--help\"]\n}\n```\n\n### WPF Application\n\n```json\n{\n  \"assemblyPath\": \"WpfApp.dll\",\n  \"typeName\": \"WpfApp.App\",\n  \"methodName\": \"Main\",\n  \"arguments\": []\n}\n```\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- [.NET Hosting APIs](https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting) - Built with .NET Hosting APIs\n- [nlohmann/json](https://github.com/nlohmann/json) - JSON for Modern C++\n\n## 📚 Additional Resources\n\n- [hostfxr API Reference](https://github.com/dotnet/runtime/blob/main/src/native/corehost/hostfxr.h)\n- [Write a custom .NET runtime host](https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayer-alex%2Fnet-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplayer-alex%2Fnet-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplayer-alex%2Fnet-host/lists"}