support .NET 10

Started by Bumk,

Bumk

Bass.LoadMe(string path) does not work in .NET 10
"System.TypeInitializationException" in Bass.Net.dll

radio42

That more sounds like a 32- vs. 64bit issue. I.e. make sure you are using the correct native external library you are loading.
Alternative use the related .GetVersion() method to see, if that also throws an exception. What lib are you loading?

Bumk

bass.dll 64bit 2.4.18.3
As a temporary solution, I copied bass.dll next to the executable file.
When using .NET 8 (9, 7, 6, etc.), this error does not occur.

radio42

#3
Are you only getting the error with the .LoadMe method. Or also when you instead call the .GetVersion method.
Both should actually load the bass.dll. The later automatically.

It might be related to this .Net10 change:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/interop/10.0/native-library-search

In Bass.Net no explicit DllImportSearchPath is specified in any P/Invoke definition.

Bumk

The BASS_GetVersion() method also throws an error.

radio42

...an error?
Is it always the TypeInitializationException?

Bumk

Yes, it's "System.TypeInitializationException" in Bass.Net.dll

radio42

Can you please post your code when you get this error (esp. when using the _GetVersion method).
And you made really sure it is not a 64 vs. 32 bit issue?!
Eg. You explicitly tested the same code with the 64Bit AND the 32bit version of the native DLL?

I wonder, how you can get the same error with _GetVersion() but at the same time say say you solved it by copying the native DLL next tho the executable.
As the _GetVersion method always works on the same folder as the executable - so how can you get an error here?

That is really puzzling to me...

Bumk

using System.IO;
using System.Windows;
using Un4seen.Bass;

namespace BassTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            string path = Path.Combine(Environment.CurrentDirectory, "BassDLL");
            //bool isLoaded = Bass.LoadMe(path);
            int version = Bass.BASS_GetVersion();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _ = Bass.FreeMe();
        }
    }
}
In .NET 10, the BASS_GetVersion() method throws a "System.TypeInitializationException" error without bass.dll.
In .NET 8, the BASS_GetVersion() method throws a different "System.DllNotFoundException" error without bass.dll.

In .NET 10, the LoadMe(string path) method throws a "System.TypeInitializationException" error with both 32-bit and 64-bit versions of bass.dll.
In .NET 8, the LoadMe(string path) method returns false for the 32-bit version of bass.dll (or returns true for the 64-bit version)

radio42

#9
I guess, you need to ask Microsoft, why they changed the exception in .Net core 10 (when a dll can not be found) to a TypeInitializationException. However, the inner exceptopn will still tell you "System.DllNotFoundException: Unable to load DLL 'bass' or one of its dependencies..."

Bass.Net works pretty fine with .Net 10 !

Regardless, I guess we might be mixing things up here.
There are two versions of Bass.Net provided:
(1) one targeting the .Net FullFramework v4.8.x (which might still be used with .Net 10)
(2) one targeting .Net core v6.0 or above

I.e. If you like to use .Net Core v10, you should use option (2) !
However, this version does NOT include the Bass.LoadMe method (as this is a pure Windows function).
As such, I assume you are using option (1)?

Can you please double-check which version of Bass.Net and which .Net Framework version you are using?

And please also try to initially (before calling any Bass method)  set the following, so that any internal version check is omitted, which might already load the bass.dll from its default location:
BassNet.OmitCheckVersion = true;(after, pls try the LoadMe method with a different path again, it should work then...)
I.e. you need to make sure, that the Bass.LoadMe method call returns true. Else the bass.dll is not properly loaded.

The other observations are logical the - as in .Net 10 the exception was changed (see the InnerException for details). I.e. now in both cases (architecture mismatch and dll not found) a TypeInitializationException is thrown.

Bumk

I am using Bass.Net 2.4.18.0 full and .NET 10.0.102 (x64) in a WPF project.

With bass.dll next to the executable, the LoadMe(string path) method returns the correct false/true value (adding BassNet.OmitCheckVersion = true; has no effect).

Without bass.dll next to the executable file and with the addition of BassNet.OmitCheckVersion = true; the LoadMe(string path) method causes the error "System.TypeInitializationException".

radio42

Ahh, now I can reproduce your issue (not the exception, but that the Bass.LoadMe method now works properly - there was another change in .Net 10 when using it in a Windows environment).
Thanks for spotting it and helping to reproduce the issue!

A new Bass.Net v2.4.18.1 update is available. So please redownload it: https://www.un4seen.com/filez/4/Bass24.Net.zip

Bumk

Yes. Problem solved. Thank you very much!