René's URL Explorer Experiment


Title: How can I add MyApp.deps.json to the hostfxr initialization sequence? · pythonnet/pythonnet · Discussion #2613 · GitHub

Open Graph Title: How can I add MyApp.deps.json to the hostfxr initialization sequence? · pythonnet/pythonnet · Discussion #2613

X Title: How can I add MyApp.deps.json to the hostfxr initialization sequence? · pythonnet/pythonnet · Discussion #2613

Description: How can I add MyApp.deps.json to the hostfxr initialization sequence?

Open Graph Description: I have the following runtimeconfig.json: { "runtimeOptions": { "tfm": "net8.0", "framework": { "name": "Microsoft.NETCore.App", "version": "8.0.0" }, "configProperties": { "System.Runtime.Serializa...

X Description: I have the following runtimeconfig.json: { "runtimeOptions": { "tfm": "net8.0", "framework": { "name": "Microsoft.NETCore.App", "ver...

Opengraph URL: https://github.com/pythonnet/pythonnet/discussions/2613

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"How can I add MyApp.deps.json to the hostfxr initialization sequence?","text":"

I have the following

\n

runtimeconfig.json:

\n
{\n  \"runtimeOptions\": {\n    \"tfm\": \"net8.0\",\n    \"framework\": {\n      \"name\": \"Microsoft.NETCore.App\",\n      \"version\": \"8.0.0\"\n    },\n    \"configProperties\": {\n      \"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization\": false\n    }\n  }\n}
\n

and I simply use this code to load the .NET runtime:

\n
    import pythonnet\n\n    path = os.path.join(\"path\", \"to\", \"app\", \"lib\", \"dotnet\")\n    sys.path.insert(0, path)\n    config_path = os.path.join(path, \"MyApp.runtimeconfig.json\")\n    pythonnet.load(\"coreclr\", runtime_config=str(config_path))\n\n    import clr\n\n    clr.AddReference(\"MyApp\")
\n

This works fine mostly, however, I noticed that if my app overrides a framework dependency e.g. upgrading System.Collections.Immutable from version 8.0.0 (provided by the framework) to 9.0.0 (provided via NuGet, but still compatible with net8.0), my application starts crashing, because the SCI version 9.0.0 cannot be loaded.

\n

After a lot debugging, I realized that this is because the MyApp.deps.json is not considered when first initializing hostfxr therefore it only ever loads the TPA version provided by the framework. See the host.log attachment for details.

\n

Unfortunately, it seems that hostfxr is considering Python.Runtime.dll the \"main assembly\" as can be seen here

\n
CoreCLR path = 'C:\\path\\to\\app\\build\\dependencies\\dotnet\\shared\\Microsoft.NETCore.App\\8.0.4\\coreclr.dll', CoreCLR dir = 'C:\\path\\to\\app\\build\\dependencies\\dotnet\\shared\\Microsoft.NETCore.App\\8.0.4\\'\nLoaded library from C:\\path\\to\\app\\build\\dependencies\\dotnet\\shared\\Microsoft.NETCore.App\\8.0.4\\coreclr.dll\n--- Invoked hostpolicy [version: 8.0.4 @Commit: 2d7eea252964e69be94cb9c847b371b23e4dd470] corehost_resolve_component_dependencies = {\n  Component main assembly path: C:\\path\\to\\app\\lib\\scripts-python3.10\\pythonnet\\runtime\\Python.Runtime.dll\n}\n-- arguments_t: app_root='C:\\path\\to\\app\\lib\\scripts-python3.10\\pythonnet\\runtime\\' deps='C:\\path\\to\\app\\lib\\scripts-python3.10\\pythonnet\\runtime\\Python.Runtime.deps.json' mgd_app='C:\\path\\to\\app\\lib\\scripts-python3.10\\pythonnet\\runtime\\Python.Runtime.dll'\n
\n

I was able to work around this by doing the following:

\n
    import pythonnet\n\n    path = os.path.join(\"path\", \"to\", \"app\", \"lib\", \"dotnet\")\n    sys.path.insert(0, path)\n    config_path = os.path.join(path, \"MyApp.runtimeconfig.json\")\n\n   runtime = clr_loader.get_coreclr(runtime_config=str(config_path))\n    \n    pythonnet.set_runtime(runtime) \n\n    libPath = os.path.join(path, \"MyApp.dll\")\n    assembly = runtime.get_assembly(str(libPath))\n\n    print(\"Loaded \" + libPath)\n\n    # just invoke an empty function to load the library\n    func = assembly.get_function(\"MyApp.Interop.Host.Initialize\")\n\n    result = func(b\"\")\n    assert result == 0, f\"Failed to initialize MyApp.dll, error code {result}\"\n    \n    pythonnet.load(runtime)\n\n    import clr\n\n    clr.AddReference(\"Python.Runtime\")\n    clr.AddReference(\"MyApp\")
\n

now, hostfxr loads the \"correct\" deps.json file, but I get a Python error whenever I do something that involves list or dict types:

\n
someManagedObj.ListProperty = get_python_list()
\n
\n

TypeError: 'list' value cannot be converted to System.Collections.Generic.IReadOnlyList`1[System.String]

\n
\n

What am I missing here? Thank you very much!

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

You are not missing anything, this is simply tricky. .NET Framework didn't have this \"problem\", and Python.NET was developed against .NET Framework.

\n

I'm not sure why the conversions are messed up in your case.

\n

Could you see whether this pythonnet/clr-loader#66 helps? It is already merged on master, just not released, yet (as I want to integrate it back into the get_coreclr factory).

","upvoteCount":1,"url":"https://github.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614"}}}

route-pattern/_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format)
route-controllervoltron_discussions_fragments
route-actiondiscussion_layout
fetch-noncev2:ffc95c0f-3375-70f4-1bbe-d191b8ac30c8
current-catalog-service-hash9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be
request-idC106:3DC7AA:F8B09B:15254B9:696FFDE3
html-safe-nonce33491bb167d10e49aa3db610a29a4d39beb3d77d818452d15d11012a16ffb760
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTA2OjNEQzdBQTpGOEIwOUI6MTUyNTRCOTo2OTZGRkRFMyIsInZpc2l0b3JfaWQiOiI2MDQwMjQ3NDc5MjA0NTc2NzM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac86e750d0b15373f9e1ed5176d18b19a354350d46678b24fc210c6342061509eb
hovercard-subject-tagdiscussion:8801905
github-keyboard-shortcutsrepository,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/discussions_fragments/discussion_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/pythonnet/pythonnet/2613/discussion_layout
twitter:imagehttps://opengraph.githubassets.com/b25ba26e8334bfeb6fcd053821a93412e1f6f80c2183f6545bb8cf4eb073f4bf/pythonnet/pythonnet/discussions/2613
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b25ba26e8334bfeb6fcd053821a93412e1f6f80c2183f6545bb8cf4eb073f4bf/pythonnet/pythonnet/discussions/2613
og:image:altI have the following runtimeconfig.json: { "runtimeOptions": { "tfm": "net8.0", "framework": { "name": "Microsoft.NETCore.App", "version": "8.0.0" }, "configProperties": { "System.Runtime.Serializa...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None0366807b865cee6776368231232f84d6c8096e6bce43f701a4fb28ea795ec427
turbo-cache-controlno-preview
go-importgithub.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git
octolytics-dimension-user_id6050430
octolytics-dimension-user_loginpythonnet
octolytics-dimension-repository_id14748123
octolytics-dimension-repository_nwopythonnet/pythonnet
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id14748123
octolytics-dimension-repository_network_root_nwopythonnet/pythonnet
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release33f356bb2fb58726ccb2f26395bf8ddc9a2d9eaa
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fdiscussions%2F2613
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fdiscussions%2F2613
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fdiscussions_fragments%2Fdiscussion_layout&source=header-repo&source_repo=pythonnet%2Fpythonnet
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
Reloadhttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
pythonnet https://patch-diff.githubusercontent.com/pythonnet
pythonnethttps://patch-diff.githubusercontent.com/pythonnet/pythonnet
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Fork 770 https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Star 5.4k https://patch-diff.githubusercontent.com/login?return_to=%2Fpythonnet%2Fpythonnet
Code https://patch-diff.githubusercontent.com/pythonnet/pythonnet
Issues 155 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues
Pull requests 18 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulls
Discussions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions
Actions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/actions
Projects 0 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/projects
Wiki https://patch-diff.githubusercontent.com/pythonnet/pythonnet/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/pythonnet/pythonnet/security
Please reload this pagehttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
Insights https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulse
Code https://patch-diff.githubusercontent.com/pythonnet/pythonnet
Issues https://patch-diff.githubusercontent.com/pythonnet/pythonnet/issues
Pull requests https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulls
Discussions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions
Actions https://patch-diff.githubusercontent.com/pythonnet/pythonnet/actions
Projects https://patch-diff.githubusercontent.com/pythonnet/pythonnet/projects
Wiki https://patch-diff.githubusercontent.com/pythonnet/pythonnet/wiki
Security https://patch-diff.githubusercontent.com/pythonnet/pythonnet/security
Insights https://patch-diff.githubusercontent.com/pythonnet/pythonnet/pulse
Answered https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614
filmorhttps://patch-diff.githubusercontent.com/filmor
siegfriedpammer-qt https://patch-diff.githubusercontent.com/siegfriedpammer-qt
Q&Ahttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/categories/q-a
How can I add MyApp.deps.json to the hostfxr initialization sequence? https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#top
siegfriedpammer-qt https://patch-diff.githubusercontent.com/siegfriedpammer-qt
Answered https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614
filmorhttps://patch-diff.githubusercontent.com/filmor
Return to tophttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#top
Please reload this pagehttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
siegfriedpammer-qt https://patch-diff.githubusercontent.com/siegfriedpammer-qt
Aug 26, 2025 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussion-8801905
host.loghttps://github.com/user-attachments/files/21983611/host.log
Give feedback.https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
filmor https://patch-diff.githubusercontent.com/filmor
Aug 26, 2025 https://github.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614
pythonnet/clr-loader#66https://github.com/pythonnet/clr-loader/pull/66
View full answer https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614
Oldest https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613?sort=old
Newest https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613?sort=new
Top https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613?sort=top
Please reload this pagehttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
filmor https://patch-diff.githubusercontent.com/filmor
Aug 26, 2025 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14219614
pythonnet/clr-loader#66https://github.com/pythonnet/clr-loader/pull/66
Give feedback.https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
https://patch-diff.githubusercontent.com/siegfriedpammer-qt
Please reload this pagehttps://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
siegfriedpammer-qthttps://patch-diff.githubusercontent.com/siegfriedpammer-qt
Aug 26, 2025 https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613#discussioncomment-14221375
Give feedback.https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
siegfriedpammer-qthttps://patch-diff.githubusercontent.com/siegfriedpammer-qt
Sign up for freehttps://patch-diff.githubusercontent.com/join?source=comment-repo
Sign in to commenthttps://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonnet%2Fpythonnet%2Fdiscussions%2F2613
🙏 Q&A https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/categories/q-a
https://patch-diff.githubusercontent.com/siegfriedpammer-qt
https://patch-diff.githubusercontent.com/filmor
https://patch-diff.githubusercontent.com/pythonnet/pythonnet/discussions/2613
https://patch-diff.githubusercontent.com/settings/replies?return_to=1
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.