Visual Studio designer crash with inherited forms if the base form contains Revit API references
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is quite a weird problem with a lot of moving parts, I'm posting here first since I managed to reproduce this issue only with the Revit API, but also planning to try and bring this to a bug report to Microsoft.
This repository showcases an issue with Visual Studio and designing inherited forms that contain external DLL references, in this case Revit API.
In this project, frmIBase contains a reference to Revit and just creates an object from its library, then Form1 inherits from that form and doesn't do anything else, in this case the visual studio editor will crash with various messages, usually "Could not load file or assembly 'RevitAPIUI, Version=25.0.0.0, Culture=neutral, PublicKeyToken=null'." or
|
I know Revit addins are not meant to run standalone and need to be hosted inside Revit, however it is normally possible to design the forms in visual studio, this can be observed by loading Form2 in the designer: that form has a direct reference, does not inherit from any other form, and loads properly in the designer.
This is not strictly a .NET 8 problem, looks like it's happening even on .net 4.8 and visual studio 2019
I made a small project that showcases the issue:
https://github.com/MaddoScientisto/FormsCrash-example
Short code samples:
Base Form:
public partial class frmIBase : Form
{
private UIDocument Uidoc = new UIDocument(null);
public frmIBase()
{
}
}
Inherited Form:
public partial class Form1 : frmIBase
{
public Form1()
{
InitializeComponent();
}
}
Control Form that can be designed normally and does not inherit:
public partial class Form2 : Form
{
private UIDocument uidoc;
public Form2()
{
InitializeComponent();
}
}
I'm hoping someone ran into this issue and knows something about this, the obvious solution would be to not use inherited forms or use WPF, but that may not always be feasible, especially in the case of older codebases.
In the sample I'm using the Revit dlls from nice3point's nuget package, this issue happens even if the original dlls from the Revit installation folder are referenced directly, it even happens for Revit 2024 on .net 8