Hello,
I am studing the .NET 7.0 support of Rhino 8 WIP and I am having some very crazy issues with library loading.
Issue Summary
Trying to be as direct as possible: A plugin that is configured to support both WinForms and WPF presents issues when loading other NuGet packages. Sometimes it fails without error message, sometimes it throws an exception stating the dll is not found.
Versions
1- VIsual Studio 2022 17.7.6 (up to date as per the VS installer)
2- Rhino extension downloaded from the VS extension manager:
3- Rhino 8 BETA version:
![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/c/6/0c65aad0eba679f71cfd8fd62d06c22280f29c0e.png)
4- Rhino NuGet package in the project (I updated using the NuGet Manager to the BETA version - the extension points to the WIP):
![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/a/f/9af75e163659ddbe3eb1509fe04bb16b72155bdc.png)
Steps to Reproduce Issue
1- Create new project Check Both Use Windows Forms and Use WPF. I need both checked because I want to host a WPF user control inside a rhino ETO panel.
2- If you try to build without changing anything, it will fail with the following error message:
error NETSDK1136: The target platform must be set to Windows (usually by including ‘-windows’ in the TargetFramework property) when using Windows Forms or WPF, or referencing projects or packages that do so.
Thus, I changed the project file with the following line (as @dale suggested in another post of mine):
<TargetFrameworks>net7.0-windows;net48</TargetFrameworks>
It builds and runs. If you call the default command, it makes the line as expected.
3- Add a 3rd party NuGet package. I will use the CsvHelper as example which I personally don’t expect to be so special:
Status: It still builds and the command adds the line.
4- Lets play with the RunCommand default function to just reference the added NuGet package.
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
// ISSUE TESTER
try
{
CsvReader reader = null; // <- ISSUE!!! COMMENT AND UNCOMMENT THIS LINE
int a = 0; // Try adding a breakpoint here
a++;
}
catch (Exception ex)
{
throw;
}
// ISSUE TESTER
// TODO: start here modifying the behaviour of your command.
// ---
RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName);
Point3d pt0;
using (GetPoint getPointAction = new GetPoint())
{
getPointAction.SetCommandPrompt("Please select the start point");
if (getPointAction.Get() != GetResult.Point)
{
RhinoApp.WriteLine("No start point was selected.");
return getPointAction.CommandResult();
}
pt0 = getPointAction.Point();
}
Point3d pt1;
using (GetPoint getPointAction = new GetPoint())
{
getPointAction.SetCommandPrompt("Please select the end point");
getPointAction.SetBasePoint(pt0, true);
getPointAction.DynamicDraw +=
(sender, e) => e.Display.DrawLine(pt0, e.CurrentPoint, System.Drawing.Color.DarkRed);
if (getPointAction.Get() != GetResult.Point)
{
RhinoApp.WriteLine("No end point was selected.");
return getPointAction.CommandResult();
}
pt1 = getPointAction.Point();
}
doc.Objects.AddLine(pt0, pt1);
doc.Views.Redraw();
RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName);
// ---
return Result.Success;
}
Note that I just added a null reference to an object of the added library.
Add a breakpoint to the int a = 0; Line.
Status: It builds (DEBUG config).
When I hit F5 Rhino runs with the debugger.
I call the command and the weird behaviour happens.
if the CsvReader reader = null; is NOT commented, the command does nothing. There is this output in the Rhino console: Command: LibLoadPluginTestCommand but nothing else. The breakpoint at line int a = 0; is not hit.
Now, if the CsvReader reader = null; IS commented, the breakpoint at line int a = 0; is hit and the normal behaviour happens.
I am having the very same issue with other libraries. If seems that the plugins cannot load other libs. I suspect it is something related to adding -windows to the target platform for net7.0 - but this is required if we are to use WinForms.
The zipped test project is herein attached:
LibLoadPluginTest.zip (422.4 KB)
Thank you for your assistance.