Closed Elvira-Kadaub closed 1 year ago
Hi @Elvira-Kadaub
Sorry to hear that you ran into this issue. Your code looks fine to me and works on Linux and Windows.
So it might be that the issue is related to the OS you are using. It seems that at least pythonnet is working since the clr.AddReference()
calls would have crashed your script on the first line otherwise.
Since I don't have access to a Mac system its hard to debug this. What you can try is to use the C# library that runs on the same DLL files and test if you can import your file there (e.g. https://github.com/PNNL-Comp-Mass-Spec/Thermo-Raw-File-Reader).
Let me know if you find out more. If there is something that we can fix on the python side, I'll gladly create an update.
I've tested this on a Mac. What version of pythonnet do you have installed? Also, have you installed Mono or .NET Core (brew install mono
or brew install dotnet
)?
Hi, thanks for looking into this issue. Here are the versions: Mono JIT compiler version 6.12.0.182 .NET SDK Version: 8.0.100-preview.4.23260.5 Pythonnet 3.0.1 MacOS Monterey
Thanks!
I'm still trying to figure out how to get it to work with .NET instead of Mono, but I have replicated the issue when using .NET:
$ echo "${PYTHONNET_RUNTIME}"
coreclr
$ python raw_file_access_example.py ~/rawfiles/testing.raw
Traceback (most recent call last):
File "/home/dpsmca/src/fisher_py/raw_file_access_example.py", line 48, in <module>
raw_file.select_instrument(Device.MS, 1)
File "/home/dpsmca/src/fisher_py/fisher_py/raw_file_reader/raw_file_access.py", line 915, in select_instrument
self._get_wrapped_object_().SelectInstrument(instrument_type.value, instrument_index)
System.NullReferenceException: Object reference not set to an instance of an object.
at ThermoFisher.CommonCore.RawFileReader.RawFileAccessBase.SelectInstrument(Device instrumentType, Int32 instrumentIndex)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
$ unset PYTHONNET_RUNTIME
$ python raw_file_access_example.py ~/rawfiles/testing.raw
Raw file: /home/dpsmca/rawfiles/testing.raw
Instrument count: 3
Instrument methods: 2
$
My setup is:
Python:
3.11.1
pythonnet:
3.0.1
Mono:
6.12.0.182
.NET SDKs installed:
8.0.100-preview.4.23260.5
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0-preview.4.23260.4
Microsoft.NETCore.App 8.0.0-preview.4.23259.5
.NET versions 6.0.408 and 7.0.302 give the same error.
It's great to see that there are other Mac users trying to figure out what the problem is. I have had another look at other projects using the same DLLs and it seems that Mono should work but .NET Core does not:
from: https://github.com/PNNL-Comp-Mass-Spec/Thermo-Raw-File-Reader
@dpsmca 's experiments seem to confirm this at least on Mac.
@dowerner , @dpsmca , thank you for checking on this!
Hello, I have a problem reading .raw file. Am I supposed to set a Device type somehow? `NullReferenceException Traceback (most recent call last) Cell In[10], line 3 1 from fisher_py import RawFile 2 from fisher_py.data.business import TraceType ----> 3 raw_file = RawFile(file_path)
File /opt/homebrew/lib/python3.11/site-packages/fisher_py/raw_file.py:61, in RawFile.init(self, path) 59 self._path = path 60 self._raw_file_access = RawFileReaderAdapter.file_factory(path) ---> 61 self._raw_file_access.select_instrument(Device.MS, 1) 63 # fetch retention times and scan numbers 64 scan_numbers, rt = self._get_scan_numbers_and_retentiontimes()
File /opt/homebrew/lib/python3.11/site-packages/fisher_py/raw_file_reader/raw_file_access.py:915, in RawFileAccess.select_instrument(self, instrument_type, instrument_index) 913 assert type(instrument_type) is Device 914 assert type(instrument_index) is int --> 915 self._get_wrappedobject().SelectInstrument(instrument_type.value, instrument_index)
NullReferenceException: Object reference not set to an instance of an object. at ThermoFisher.CommonCore.RawFileReader.RawFileAccessBase.SelectInstrument(Device instrumentType, Int32 instrumentIndex) in C:\Thermofisher\Projects\1\s\Libraries\RawFileReader\RawFileAccessBase.cs:line 2368 at InvokeStub_IRawData.SelectInstrument(Object, Object, IntPtr) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr args, BindingFlags invokeAttr)`