pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.28k stars 331 forks source link

[Bug]: Can't run C# pushbutton #2375

Open nguyenthanhson1712 opened 3 weeks ago

nguyenthanhson1712 commented 3 weeks ago

✈ Pre-Flight checks

🐞 Describe the bug

image I can't run the code test C# of "Test C# Script.pushbutton" Although I got it running on pyrevit version 4.8.16.24121

⌨ Error/Debug Message

C# Traceback:
Define: REVIT2025;REVIT2025_2 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Private.CoreLib.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\AdWindows.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Emojis.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.TargetApps.Revit.dll 
Reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Web.dll 
Reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Numerics.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.NLog.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.MahAppsMetro.dll 
Reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Xml.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\Xceed.Wpf.AvalonDock.dll 
Reference: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\RevitAPIUI.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\Microsoft.CSharp.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.PyRevit.Runtime.Shared.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLoader.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.IronPython.Modules.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\PresentationFramework.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\PresentationCore.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Common.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.IronPython.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.Microsoft.Scripting.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Xaml.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\WindowsBase.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\WindowsFormsIntegration.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\UIFramework.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Json.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Core.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.Microsoft.Dynamic.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\bin\Markdown.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Drawing.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.CommonWPF.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.PyRevit.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\RevitAPI.dll 
Reference: C:\Users\ADMIN\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.PyRevit.Runtime.2025.dll 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(18,16): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(18,23): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(16,44): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(19,20): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(19,13): error CS0012: The type 'MulticastDelegate' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(20,20): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(20,13): error CS0012: The type 'MulticastDelegate' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(21,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(25,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(28,24): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(28,13): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(31,24): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(31,13): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(37,36): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(38,28): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(38,17): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(42,28): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(42,17): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(45,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(45,51): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(46,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(47,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(49,31): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(50,13): error CS0103: The name 'Console' does not exist in the current context 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(54,20): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
C:\Users\ADMIN\AppData\Roaming\pyRevit\Extensions\pyRevitDevTools.extension\pyRevitDev.tab\Debug.panel\Bundle Tests.pulldown\Test C# Script.pushbutton\script.cs(54,27): error CS0012: The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

♻️ To Reproduce

No response

⏲️ Expected behavior

🖥️ Hardware and Software Setup (please complete the following information)

Additional context

acco-jpitts commented 3 weeks ago

Revit 2025 use .NET 8.0, so any DLLs/dependencies must be built using .NET 8.0 as well. This Dev extension has not been updated for 2025. Its using .Netframework 4.8 which covers at least 2020-2024 and probably even earlier versions as well.

nguyenthanhson1712 commented 3 weeks ago

Revit 2025 use .NET 8.0, so any DLLs/dependencies must be built using .NET 8.0 as well. This Dev extension has not been updated for 2025. Its using .Netframework 4.8 which covers at least 2020-2024 and probably even earlier versions as well.

I tried in Revit version 2022 (pyrevit version 5.0.0) but got the same error as version 2025, should I wait for the bug to be fixed?

acco-jpitts commented 3 weeks ago

did you use latest WIP?

Looks like they were already discussing this issue in this merged pull request.

sanzoghenzo commented 3 weeks ago

Try the latest WIP installer: yesterday #2373 came up, and it was solved with #2374 4 hours before you filed the issue.

It may be that some libraries are still missing, let us know if you still got errors

nguyenthanhson1712 commented 3 weeks ago

Try the latest WIP installer: yesterday #2373 came up, and it was solved with #2374 4 hours before you filed the issue.

It may be that some libraries are still missing, let us know if you still got errors

Sorry, I missed the information. I uninstalled the old WIP version and reinstalled the WIP version "pyRevit_5.0.0.24236_admin_signed", my C# code worked, but now I have 2 errors.

  1. pyRevit is broken in version 2022, version 2025 is working.
  2. Console.WriteLine() is broken, although when I tried the same code in pyRevit version 4.8.16, the code still ran

image image

sanzoghenzo commented 3 weeks ago

Thanks for the report, I should have expected incompatibilities with previous versions :sweat_smile:

The first error stems from this line:

https://github.com/pyrevitlabs/pyRevit/blob/a0c78748bab188bb81f4f5c3b9c07bfdff144d41/pyrevitlib/pyrevit/runtime/__init__.py#L277

It the assembly is not found, a None object is placed in the list instead of dropping it. A quick way to solve this is to change the line to the following:

refs = (_get_reference_file(ref_name) for ref_name in ref_list)
return [r for r in refs if r]

Can you please have a try with this code?

For the Console problem: If it is not already there, try to explicitly add using System; to your script; If it is there, try to add System.Console to the list above the aforementioned line.

Lastly, a little ask: please don't use screenshots when you can copy paste the code; it will help us help you more quickly to have a copy-paste-able minimum reproducible example to test with (that's why I wrote you what it could be done to fix this issue, I'm to lazy to test things myself :rofl: )