# Upstream updated C# bindings for AOT compilation

**URL:** <https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636>\
**Category:** FMOD Engine\
**Tags:** csharp\
**Created:** [May 19, 2024, 11:01am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636 "2024-05-19T11:01:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joskuijpers-jarvix](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joskuijpers-jarvix/32/6709_2.png) [@joskuijpers-jarvix](https://qa.fmod.com/u/joskuijpers-jarvix)\
**Post date:** [May 19, 2024, 11:01am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636/1 "2024-05-19T11:01:43Z")

</div>

Hi,

I’ve made a change locally to the fmod.cs bindings in order to solve AOT warnings and potential issues.  
I’d like to share them so they can be upstreamed, or can be used to fix upstream.

The core part:

- replace the likes of `get { return nonblockcallback_internal == IntPtr.Zero ? null : (SOUND_NONBLOCK_CALLBACK)Marshal.GetDelegateForFunctionPointer(nonblockcallback_internal, typeof(SOUND_NONBLOCK_CALLBACK)); }` with ` get { return nonblockcallback_internal == IntPtr.Zero ? null : (SOUND_NONBLOCK_CALLBACK)Marshal.GetDelegateForFunctionPointer<SOUND_NONBLOCK_CALLBACK>(nonblockcallback_internal); }` (using Generics instead of passing Type)
- Using generics version of Marshal.SizeOf() and Marshal.PtrToStructure().

Is there anywhere I can send this, or another way I can help getting this change upstreamed?

EDIT: Ah I see now it says “Use the old syntax (non-generic) to ensure maximum compatibility (especially with Unity) ignoring the warnings”. This can break AOT builds that do not use Unity. Any way to solve this, maybe with two generated cs versions?

---

<div class="post-metadata">

**Author:** ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)\
**Post date:** [May 22, 2024, 12:42am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636/2 "2024-05-22T00:42:18Z")

</div>

Hi,

Thank you for sharing the fix to address the AOT warning!

> [@joskuijpers-jarvix](#):
>
> Ah I see now it says “Use the old syntax (non-generic) to ensure maximum compatibility (especially with Unity) ignoring the warnings”.

I have tried to switch the scripting backend to IL2CPP and used the Unity Burst for AOT compilation.

Unfortunately, I was not able to reproduce the warning message you mentioned above, could you please let me know the version number of the Unity and FMOD Unity integration plugin you are using?

Would it be possible to share the logs and elaborate a bit more about how to reproduce the issue?

---

<div class="post-metadata">

**Author:** ![joskuijpers-jarvix](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joskuijpers-jarvix/32/6709_2.png) [@joskuijpers-jarvix](https://qa.fmod.com/u/joskuijpers-jarvix)\
**Post date:** [May 22, 2024, 7:54am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636/3 "2024-05-22T07:54:59Z")

</div>

I was not clear before:  
I am not using Unity but a bespoke C# solution with dotnet 8 (Core). This has AOT support, which is not IL2CPP.

AOT has some requirements or warnings around trimming of code.

I see the current c# code is tailored for the Unity users. For the core-aot users, generics need to be employed so trimming does not cause issues.

If you make a new c# console app, add the fmod cs file, enable aot and build it you’ll get the warnings.

---

<div class="post-metadata">

**Author:** ![li\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/li_fmod/32/6577_2.png) [@li\_fmod](https://qa.fmod.com/u/li_fmod)\
**Post date:** [May 24, 2024, 5:59am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636/4 "2024-05-24T05:59:46Z")

</div>

Thank you for the detailed information!

I have managed to reproduce the warnings and workaround it with your method, I can clearly see how useful this solution is, and I will pass it on to our development team to look into further.

In the meantime, please feel free to modify the scripts and let me know if you have any further questions.

---

<div class="post-metadata">

**Author:** ![photex1](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/photex1/32/5337_2.png) [@photex1](https://qa.fmod.com/u/photex1)\
**Post date:** [July 24, 2024, 7:04am UTC](https://qa.fmod.com/t/upstream-updated-c-bindings-for-aot-compilation/21636/5 "2024-07-24T07:04:28Z")

</div>

If it isn’t too much trouble or work, could you export your fixes as a \*.patch and upload it here for the rest of us. 😃
