mikeoliphant / AudioPlugSharp

Easily create VST (VST3) audio plugins in C# .NET
MIT License
177 stars 21 forks source link

Unhandled exception when loading WPF and non GUI plugins into DAW #29

Closed adrianmcroft closed 3 weeks ago

adrianmcroft commented 2 months ago

So, this isn't a big deal as I can create all of my Plugins as WPF versions, I just wondered if it rings true...

When I try and load the vanilla Simple or MidiExample along with WPFExample, I get this exception and Reaper / VSTHost closes.

Unhandled exception at 0x00007FFEBCCF6D9A in reaper.exe: Microsoft C++ exception: long at memory location 0x0000000000142630.

The debugger Output window also receives 'The specified framework 'Microsoft.NETCore.App', version '6.0.0', apply_patches=1, version_compatibility_range=minor is incompatible with the previously loaded version '8.0.8'.Failed to start the .NET runtime. Error code -2147450715Exception thrown at 0x00007FFEBCCF6D9A in reaper.exe: Microsoft C++ exception: long at memory location 0x0000000000142630.'

I also don't know why 8.0.8 is mentioned when all projects are targetting 6.

It's not a showstopper at all as I'm now plowing along with development, If the hive mind has some insight I'd be grateful.

mikeoliphant commented 2 months ago

The .NET framework version of your plugin project actually does not determine the version of the framework that gets used. Because the AudioPlugSharp bridge assembly gets loaded first, it determines the version.

If you have a look at the "Bridge.runtimeconfig.json" file, you can see what .NET version is being specified.

If you see "rollForward": "LatestMajor", then it will use the latest major version of .NET that you have installed. That is where the .NET 8.0 is coming from. If you delete that line from your WPF config, it should work.

In general, the "rollForward" behavior is preferred so that all plugins will have the same .NET version. Right now, however, there is an issue in .NET 8.0 that is preventing multiple plugins from being loaded properly.

I submitted a PR to the .NET runtime to fix the problem:

https://github.com/dotnet/runtime/pull/105337

This fix has been merged and will be released soon with .NET 9.0 (and I think it will also get backported to .NET 8.0).

For now, though, your best bet is to make sure the runtime config for all of your plugins specifies .NET 6.0 and does not have rollForward enabled.

I'll leave this issue open until .NET 9.0 is out and I've upgraded AudioPlugSharp to use it.

adrianmcroft commented 1 month ago

Many thanks Mike. And thanks for the detailed explanation and your time.

I'll admit that I go cross-eyed when I step back from 8 - and I can't even remember what the 'improvements' were, so I'll plod on as-is with 8 and the WPF runtime version, as I have a long development ahead and I'll revisit when 9 drops officially.

mikeoliphant commented 3 weeks ago

The fix for this has now been backported and released for .NET 8.0. I've now update AudioPlugSharp to .NET 8.0 and have updated the runtime configs.

All should now work well with the latest AudioPlugSharp nuget packages and the latest version of .NET 8.0, so I'm going to close this issue.