MHDante / pythonnet-stub-generator

Creates Python Type Hints for Python.NET libraries
MIT License
19 stars 9 forks source link

[help needed] Could not load file or assembly #6

Open miguelmaso opened 3 months ago

miguelmaso commented 3 months ago

Hi @MHDante , first of all, thanks for developing this tool. I'm trying to generate the stubs for a dll that I'm importing into Python because it's very annoying yo have the idle with a lot of missing imports and no linting.

When executing the tool GeneratePythonNetStubs I get an error and I don't know how to proceed. Maybe related to #5

PS C:\Users\mmaso\.dotnet\tools> .\GeneratePythonNetStubs.exe --dest-path .\ --target-dlls 'C:\Program Files\Autodesk\Revit 2025\RevitAPI.dll'
building stubs...
error: failed generating stubs | Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. El sistema no puede encontrar el archivo especificado.
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. El sistema no puede encontrar el archivo especificado.
File name: 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at PythonNetStubGenerator.StubBuilder.BuildAssemblyStubs(DirectoryInfo destPath, FileInfo[] targetAssemblyPaths, DirectoryInfo[] searchPaths) in C:\Repos\pythonnet-stub-generator\csharp\PythonNetStubGenerator\StubBuilder.cs:line 22
   at PythonNetStubTool.Program.Main(DirectoryInfo destPath, String targetDlls, DirectoryInfo[] searchPaths) in C:\Repos\pythonnet-stub-generator\csharp\PythonNetStubTool\Program.cs:line 42
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<AddMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
PS C:\Users\mmaso\.dotnet\tools>
miguelmaso commented 3 months ago

Depending on the dll file and the version I'm getting different errors:

PS C:\Users\mmaso\.dotnet\tools> .\GeneratePythonNetStubs.exe --dest-path .\2022\ --target-dlls 'C:\Program Files\Autodesk\Revit 2022\RevitAPIUI.dll'
building stubs...
Generating Assembly: RevitAPIUI, Version=22.0.0.0, Culture=neutral, PublicKeyToken=null
error: failed generating stubs | Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. El sistema no puede encontrar el archivo especificado.
PS C:\Users\mmaso\.dotnet\tools> .\GeneratePythonNetStubs.exe --dest-path .\2025\ --target-dlls 'C:\Program Files\Autodesk\Revit 2025\RevitAPIUI.dll'
building stubs...
error: failed generating stubs | Could not load file or assembly 'C:\Program Files\Autodesk\Revit 2025\RevitAPIUI.dll'. No se puede encontrar el módulo especificado.