Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: script.cs tools in custom extension not working #2373

Closed
5 tasks done
Dre-Tas opened this issue Aug 22, 2024 · 8 comments
Closed
5 tasks done

[Bug]: script.cs tools in custom extension not working #2373

Dre-Tas opened this issue Aug 22, 2024 · 8 comments
Labels
Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] DotNet API Issues related to pyRevitLabs libraries [subsystem] pyRevit 5 pyRevit 5 coming release Revit 2025
Milestone

Comments

@Dre-Tas
Copy link
Contributor

Dre-Tas commented Aug 22, 2024

✈ Pre-Flight checks

  • I don't have SentinelOne antivirus installed (see above for the solution)
  • I have searched in the issues (open and closed) but couldn't find a similar issue
  • I have searched in the pyRevit Forum for similar issues
  • I already followed the installation troubleshooting guide thoroughly
  • I am using the latest pyRevit Version

🐞 Describe the bug

We have a few buttons in our internally developed pyRevit extension (Wombat) that are based off a script.cs script and they all don't work with the new pyRevit 5.
I also got rid of all the code inside of the Execute method to check if there was something there it didn't like but still getting an error (pasted below).

The buttons that have a script.py script seem to be working.

Is this a known issue?
I thought of letting you know.

⌨ 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:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.CommonWPF.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Drawing.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\AdWindows.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\RevitAPI.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\WindowsBase.dll 
Reference: C:\windows\Microsoft.NET\Framework64\v4.0.30319\System.Web.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.MahAppsMetro.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Numerics.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLoader.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.PyRevit.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Windows.Forms.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Xml.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\System.Xaml.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Emojis.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Common.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.IronPython.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\UIFramework.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.TargetApps.Revit.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.Core.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\WindowsFormsIntegration.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.IronPython.Modules.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.Json.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\8.0.8\System.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\Xceed.Wpf.AvalonDock.dll 
Reference: C:\Program Files\Autodesk\Revit 2025\RevitAPIUI.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\PresentationCore.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.Microsoft.Dynamic.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.NLog.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\pyRevitLabs.PyRevit.Runtime.Shared.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.Microsoft.Scripting.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\Microsoft.CSharp.dll 
Reference: C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\8.0.8\PresentationFramework.dll 
Reference: C:\Users\sydata\AppData\Roaming\pyRevit-Master\bin\netcore\engines\IPY2712PR\pyRevitLabs.PyRevit.Runtime.2025.dll 
C:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(12,32): error CS0012: The type 'Attribute' 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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(12,44): 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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(12,6): 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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(15,34): 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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(15,41): 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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(61,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:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension\Wombat.tab\Views.panel\RenameAndRenumber.stack\Renumber.pushbutton\script.cs(61,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

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Renumber
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class DetailViewsNumbers : IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
           ref string message, ElementSet elements)
        {
            return Result.Succeeded;
        }
    }
}

⏲️ Expected behavior

No response

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

==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "5.0.0.24232+2108-wip" | Path: "C:\Users\sydata\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "Autodesk Revit 2025" | Engine: DEFAULT (2712) | Path: "C:\Users\sydata\AppData\Roaming\pyRevit-Master"
master | Product: "23.1.4" | Engine: DEFAULT (2712) | Path: "C:\Users\sydata\AppData\Roaming\pyRevit-Master"
master | Product: "2022.1.6" | Engine: DEFAULT (2712) | Path: "C:\Users\sydata\AppData\Roaming\pyRevit-Master"
master | Product: "2020.2.9" | Engine: DEFAULT (2712) | Path: "C:\Users\sydata\AppData\Roaming\pyRevit-Master"
==> Installed Extensions
wombatrvt | Type: Unknown | Repo: "https://[email protected]/woodsbagot/wombatrvt.git" | Installed: "C:\Temp\Revit2025Test\wombat25.extension\wombatrvt.extension"
==> Default Extension Search Path
C:\Users\sydata\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Temp\Revit2025Test\wombat25.extension
==> Extension Sources - Default
https://github.com/pyrevitlabs/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
Autodesk Revit 2025 | Version: 25.0.2.419 | Build: 20240307_1300(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2025\"
23.1.4 | Version: 23.1.40.56 | Build: 20240411_0945(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
2022.1.6 | Version: 22.1.60.18 | Build: 20240417_1700(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
2020.2.9 | Version: 20.2.90.12 | Build: 20220517_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
==> Running Revit Instances
PID: 4812 | 2025.2 | Version: 25.2.0.38 | Build: 20240715_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2025"
==> User Environment
Microsoft Windows 10 [Version 10.0.19045]
Executing User: WB\sydata
Active User: WB\sydata
Admin Access: No
%APPDATA%: "C:\Users\sydata\AppData\Roaming"
Latest Installed .Net Framework: 8.0.8
Installed .Net Target Packs: v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.7 v4.7.1 v4.7.2 v4.8 v4.X
Installed .Net-Core Target Packs: v3.1.426 v8.0.108 v8.0.300
pyRevit CLI v5.0.0.24232+2108-wip.f944ebd8245871bb1340f3a59eecff955ed411ad

Additional context

No response

@Dre-Tas Dre-Tas added the Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] label Aug 22, 2024
@sanzoghenzo
Copy link
Contributor

I believe this boils down to this:

You must add a reference to assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

it seems that the C# script executor doesn't load the needed assemblies.
I see that the original message had the error regarding your code, are all those elements part of the Revit API or are you also including external libraries? (just to get a bigger picture of what's going on).

I would be great to have the minimum reproducible example in the "To Reproduce" section 😉

@Dre-Tas
Copy link
Contributor Author

Dre-Tas commented Aug 22, 2024

Thanks for your reply @sanzoghenzo !

I just updated the post to add the code I'm trying to run. Super simple there's just nothing there ;)

Re the original post, I initially tried without the using statements and got that first error message. If you reckon it's more useful I'm happy to edit the post to reflect that.

Re the missing reference, that's missing on the pyRevit side, not my side, right?

@sanzoghenzo
Copy link
Contributor

Thanks for your reply @sanzoghenzo !

I just updated the post to add the code I'm trying to run. Super simple there's just nothing there ;)

Thank you! To troubleshoot things, super simple examples are always better than nothing at all 😉

Re the original post, I initially tried without the using statements and got that first error message. If you reckon it's more useful I'm happy to edit the post to reflect that.

It's OK as it is, if the using statements solved those particular errors, it means that the revit api is correctly loaded and available to the script.

Re the missing reference, that's missing on the pyRevit side, not my side, right?

I believe it is a pyRevit.Runtime/CLREngine.cs issue, it doesn't make available the System.Runtime assembly (and who knows what other dlls are not loaded...)

@sanzoghenzo sanzoghenzo added DotNet API Issues related to pyRevitLabs libraries [subsystem] pyRevit 5 pyRevit 5 coming release Revit 2025 labels Aug 22, 2024
@sanzoghenzo sanzoghenzo added this to the pyRevit 5 RC milestone Aug 22, 2024
@sanzoghenzo
Copy link
Contributor

After a bit of scouting, I the references loaded by the CLREngine are those defined in the pyrevit\runtume\__init__.py module here:

https://github.com/pyrevitlabs/pyRevit/blob/develop/pyrevitlib/pyrevit/runtime/__init__.py#L243-270

You can try to add System.Runtime to that list and see if it solves this (and maybe iterate for each new error it comes up).

I'll to some tests myself as soon as I have the time

@Dre-Tas
Copy link
Contributor Author

Dre-Tas commented Aug 23, 2024

That actually worked!
I made a new in case it helps #2374

@jmcouffin
Copy link
Contributor

Fixed by #2374
Please try the wip installers just to confirm @Dre-Tas

@Dre-Tas
Copy link
Contributor Author

Dre-Tas commented Aug 26, 2024

Hey @jmcouffin I just uninstalled pyRevit, cleaned up all remaining files from the system, reinstalled with new installer and C# scripts work just fine ;)

@jmcouffin
Copy link
Contributor

excellent, thanks for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug that stops user from using the tool or a major portion of pyRevit functionality [class] DotNet API Issues related to pyRevitLabs libraries [subsystem] pyRevit 5 pyRevit 5 coming release Revit 2025
Projects
Status: Done
Development

No branches or pull requests

3 participants