'无法从程序集“System.Runtime,版本 = 4.0.0.0”加载类型“System.IO.Directory”'

问题描述 投票:0回答:1

我尝试使用 C# 创建一个 .dll 文件,然后使用 pythonnet 在 Python 中执行该函数。但是,我遇到以下错误:

System.TypeLoadException: Could not load type 'System.IO.Directory' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

环境:

Pythonnet = 3.x

Python = 3.9

净=7.0

.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="FLEXlm_C_sharp">
      <HintPath>FLEXlm_C_sharp.dll</HintPath>
    </Reference>
  </ItemGroup>

  <Target Name="CopyLicDllAfterBuild" AfterTargets="Build">
    <Exec Command="xcopy &quot;$(ProjectDir)\lmgr11_64.dll&quot; &quot;$(TargetDir)&quot; /Y /I" />
  </Target>
  <Target Name="CopyLicDllAfterPublish" AfterTargets="Publish">
    <Exec Command="xcopy &quot;$(ProjectDir)\lmgr11_64.dll&quot; &quot;$(PublishDir)&quot; /Y /I" />
  </Target>
</Project>

Python


import clr
import os

dll_directory = "./"
clr.AddReference(os.path.join(dll_directory, "LicenseService_Dll.dll"))
clr.AddReference(os.path.join(dll_directory, "FLEXlm_C_sharp.dll"))

from Verifai.Infra.Service.Repository import FlexlmLicenseService
license_service = FlexlmLicenseService()
directory_path = r"D:\LicenseService\pythonDll"
status = license_service.CheckOutUsingLicenseSettings(directory_path)

我遇到错误:“无法从程序集“System.Runtime,Version=4.0.0.0”加载类型“System.IO.Directory””。

任何解决此问题的帮助将不胜感激。

python c# .net python.net
1个回答
0
投票

我遇到了同样的问题,并通过将 Visual Studio 更新到最新版本解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.