I am trying to create a .dll file using C# and then execute the function in Python using pythonnet. However, I am encountering the following error:
System.TypeLoadException: Could not load type 'System.IO.Directory' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Environment:
Pythonnet = 3.x
Python = 3.9
NET = 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 "$(ProjectDir)lmgr11_64.dll" "$(TargetDir)" /Y /I" />
</Target>
<Target Name="CopyLicDllAfterPublish" AfterTargets="Publish">
<Exec Command="xcopy "$(ProjectDir)lmgr11_64.dll" "$(PublishDir)" /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:LicenseServicepythonDll"
status = license_service.CheckOutUsingLicenseSettings(directory_path)
I am encountering the error: ‘Could not load type “System.IO.Directory” from assembly “System.Runtime, Version=4.0.0.0″‘.
Any help to resolve this issue would be greatly appreciated.
New contributor
Rodo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.