ros2-dotnet / ros2_dotnet

.NET bindings for ROS2
Apache License 2.0
136 stars 54 forks source link

fail to run rcldotnet_examples on win10 OS,throw System.ArgumentNullException #119

Open cqulpj opened 9 months ago

cqulpj commented 9 months ago

my PC system is win10, the ros2 version is foxy, visual studio 2019, .net 3.1/6/7, first, every steps of build was ok, but when I try run the examples, it throw Exceptions, the error messages as follow:

PS C:\opt\ros_dotnet_ws> .\install\local_setup.ps1 PS C:\opt\ros_dotnet_ws> ros2 run rcldotnet_examples rcldotnet_talker

Unhandled Exception: System.TypeInitializationException: The type initializer for 'ROS2.RCLdotnetDelegates' threw an exception. ---> System.ArgumentNullException: Value cannot be null. Parameter name: ptr at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t) at ROS2.RCLdotnetDelegates..cctor() in C:\opt\ros_dotnet_ws\src\ros2_dotnet\ros2_dotnet\rcldotnet\RCLdotnet.cs:line 451 --- End of inner exception stack trace --- at ROS2.RCLdotnet.Init() in C:\opt\ros_dotnet_ws\src\ros2_dotnet\ros2_dotnet\rcldotnet\RCLdotnet.cs:line 1399 at ConsoleApplication.RCLDotnetTalker.Main(String[] args) in C:\opt\ros_dotnet_ws\src\ros2_dotnet\ros2_dotnet\rcldotnet_examples\RCLDotnetTalker.cs:line 12

who can give me some suggestions, well regards.

SiebeVerhoeven commented 7 months ago

I've not particularly solved the problem, but I found something.

the rcldotnet_native.dll file is made in the _dllLoadUtils this file has a few ten's of functions. For me the file misses 2 functions that are needed in the RCLDotnet.cs. so I commented them out and now it works fine for me. only thing i'm concerned about is that I now miss these 2 functions. I guess these are not needed for me. but maybe someone can explain what these functions are for:

// IntPtr native_rcl_take_response_ptr = // _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_take_response"); // RCLdotnetDelegates.native_rcl_take_response = // (NativeRCLTakeResponseType)Marshal.GetDelegateForFunctionPointer( // native_rcl_take_response_ptr, typeof(NativeRCLTakeResponseType));

// IntPtr native_rcl_write_to_qos_profile_handle_ptr = // _dllLoadUtils.GetProcAddress(nativeLibrary, "native_rcl_write_to_qos_profile_handle"); // RCLdotnetDelegates.native_rcl_write_to_qos_profile_handle = // (NativeRCLWriteToQosProfileHandleType)Marshal.GetDelegateForFunctionPointer( // native_rcl_write_to_qos_profile_handle_ptr, typeof(NativeRCLWriteToQosProfileHandleType));

hoffmann-stefan commented 7 months ago

@cqulpj, @SiebeVerhoeven: Sorry for the late reply, currently my "spare" time I can allocate for this project is used to get the open PRs done. I tried to setup ros2_dotnet on windows once, but didn't have time to continue yet.

@SiebeVerhoeven did you try a cleen rebuild? Those functions should be defined in the c part of the library, so not sure how they would be missing for you.