惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
P
Palo Alto Networks Blog
P
Proofpoint News Feed
AI
AI
Help Net Security
Help Net Security
S
Securelist
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cisco Blogs
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
T
Tenable Blog
H
Help Net Security
NISL@THU
NISL@THU
F
Fortinet All Blogs
博客园_首页
G
GRAHAM CLULEY
L
LINUX DO - 最新话题
P
Privacy International News Feed
G
Google Developers Blog
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
The Register - Security
The Register - Security
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
Forbes - Security
Forbes - Security
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
D
Docker
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog

博客园 - 神游虚空

解决 GDAL 用 C# 访问时,中文乱码问题。 学习AI编程 安装 RAGFlow 安装 KTransformer 量化投资赚的哪方面的钱? 使用 Open XML SDK 实现 html 富文本转换为 docx 格式示例 在python中 先调用C#的dll 返回了一个类的列表,如何把这个列表转换为 python 中的 DataFrame? vue项目服务器部属源码调试解决办法 vue3 + ts + element_plus 创建后台管理系统,学习记录 大A指数周内效应分析 两个通达信公式 如何在.netcore 上实现 Rbac 权限管理 修道是精神上的减熵过程 BPMN2.0 Specifaction 节选翻译,10.4.6 事件处理(handling Events,原文 275页) BPMN2.0 Specifaction 节选翻译,10.4 事件 Events (原文233页) 使用ef或dbcontext的时候主要注意三个问题 EFCore 中 group 分组后,只选出每组中含有最大值的数据行 BPMN2.0 Specifaction 节选翻译,10.2.8 循环特征 Loop Characteristics (原文 189页) BPMN2.0 Specifaction 节选翻译,10.2.5 子流程 Sub-Processes (原文173页) BPMN2.0 Specifaction 节选翻译,10 Process (原文145页)
python中调用 .net 的 dll 时,报错:Exception has occurred: TypeLoadException
神游虚空 · 2024-11-23 · via 博客园 - 神游虚空

1、遇到问题

     在 python3 中想调用 .net8 的 dll 。在运行时报错:

Exception has occurred: TypeLoadException
未能从程序集“System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”中加载类型“System.Runtime.CompilerServices.NullableContextAttribute”。
   在 System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   在 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   在 System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   在 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)

  

2、解决办法

     这是因为无法加载 .netcore 的运行库。可以用如下方式加载对应的运行库:其中的目录改为你自己的内容。

from clr_loader import get_coreclr
from pythonnet import set_runtime

rt = get_coreclr(runtime_config="E:/Working/NTrade_New/PyNTrade/bin/Debug/net8.0/PyNTrade.runtimeconfig.json")
set_runtime(rt)

import clr
import sys

sys.path.append(r"E:/Working/NTrade_New/PyNTrade/bin/Debug/net8.0")
clr.AddReference(r"PyNTrade")

from PyNTrade import TestClass

tt = TestClass()
sum = tt.Add(1, 2)
print(sum)