# IL2CPP doesn't support ReadOnlyMemory\<T\> or ReadOnlySpan\<byte\> method parameters

**URL:** <https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544>\
**Category:** Scripting\
**Tags:** Scripting, Il2cpp, Bug\
**Created:** [April 7, 2023, 5:23pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544 "2023-04-07T17:23:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gekctek](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gekctek/32/376090_2.png) [@Gekctek](https://discussions.unity.com/u/Gekctek)\
**Post date:** [April 7, 2023, 5:23pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/1 "2023-04-07T17:23:03Z")

</div>

I have a C# .netstandard2.1 project [GitHub - BoomDAO/ICP.NET: A library for .NET/C#/Unity to natively communicate with the Internet Computer (ICP)](https://github.com/edjCase/ICP.NET/) that game developers are trying to use with their Unity games but there is a problem when compiling to WebGL/IL2CPP. Any instance where a method is called that has ReadOnlyMemory (readonly struct) or ReadOnlySpan (readonly ref struct) it gives the following message:

```auto
Building Library\Bee\artifacts\WebGL\GameAssembly\release_WebGL_wasm\8hlh_.ICP.Agent.o failed with output:
C:\Git\icp.net_demo\ICP_demo_unity\Library\Bee\artifacts\WebGL\il2cppOutput\cpp\EdjCase.ICP.Agent.cpp:10541:3: error: no matching function for call to 'CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4'
CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4(L_15, L_14, 1, (bool)0, NULL);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Git\icp.net_demo\ICP_demo_unity\Library\Bee\artifacts\WebGL\il2cppOutput\cpp\EdjCase.ICP.Agent.cpp:3562:41: note: candidate function not viable: no known conversion from 'ReadOnlyMemory_1_t63F301BF893B0AB689953D86A641168CA66D2399' to 'ReadOnlyMemory_1_t43203E8B19A7F4A97A9A49363F67C206E8B058FE' for 2nd argument
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR void CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4 (CborReader_tD16D04772AB3E74EA1866DBEC07FFFD66AC95CE5*__this, ReadOnlyMemory_1_t43203E8B19A7F4A97A9A49363F67C206E8B058FE ___0_data, int32_t___ 1_conformanceMode, bool ___2_allowMultipleRootLevelValues, const RuntimeMethod* method) ;

```

Where the method signature is `(ReadOnlyMemory<byte> data, CborConformanceMode conformanceMode = CborConformanceMode.Strict, bool allowMultipleRootLevelValues = false)`

There are a few other dead forum posts that have similar issues:

> [@IL2CPP-Build failing: "no matching function for call" linking to addressable function](https://discussions.unity.com/t/841721):
>
> Unity 2019.4.261f I can't build my android project with IL2CPP (ARMv7 & ARM64) selected. Working fine in Mono. I know IL2CPP issues seam to be quite common, but and I tried all the fixes I could find, nothing worked. My error is different though then any I have seen online and it somehow seams to be linked with addressables? (Screenshot) I have started a new project and added Addressables, there is no problem. I have removed the addressables and reinstalled them, as well as trying it with…

> [@"No matching function for call" with il2cpp in Unity 2019.4.8f1 LTS](https://discussions.unity.com/t/807279):
>
> Hi. I have been trying to track the source of this problem for a long time now and I clearly need help. I am trying to migrate my projecto 2019 LTS. Everything works great in Editor, Android Mono builds work and Windows builds too. When I try to compile for Android using il2cpp, errors occur stating that some RenderPipeline class methods (that were removed in 2019) need 3 methods instead of 2. Nowhere in my code I even reference these classes. Any help would be greatly appreciated. Building…

Any thoughts on how to resolve this or and potential fixes that can happen.

Using mono instead of IL2CPP has no issues

---

<div class="post-metadata">

**Author:** ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)\
**Post date:** [April 10, 2023, 12:18pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/2 "2023-04-10T12:18:46Z")

</div>

> [@Gekctek](#):
>
> I have a C# .netstandard2.1 project [https://github.com/edjCase/ICP.NET/](https://github.com/edjCase/ICP.NET/) that game developers are trying to use with their Unity games but there is a problem when compiling to WebGL/IL2CPP. Any instance where a method is called that has ReadOnlyMemory (readonly struct) or ReadOnlySpan (readonly ref struct) it gives the following message:
> 
> ```auto
> Building Library\Bee\artifacts\WebGL\GameAssembly\release_WebGL_wasm\8hlh_.ICP.Agent.o failed with output:
> C:\Git\icp.net_demo\ICP_demo_unity\Library\Bee\artifacts\WebGL\il2cppOutput\cpp\EdjCase.ICP.Agent.cpp:10541:3: error: no matching function for call to 'CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4'
> CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4(L_15, L_14, 1, (bool)0, NULL);
> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> C:\Git\icp.net_demo\ICP_demo_unity\Library\Bee\artifacts\WebGL\il2cppOutput\cpp\EdjCase.ICP.Agent.cpp:3562:41: note: candidate function not viable: no known conversion from 'ReadOnlyMemory_1_t63F301BF893B0AB689953D86A641168CA66D2399' to 'ReadOnlyMemory_1_t43203E8B19A7F4A97A9A49363F67C206E8B058FE' for 2nd argument
> IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR void CborReader__ctor_m5191B60B1242ACF099DE8349ED037D0A17E36DD4 (CborReader_tD16D04772AB3E74EA1866DBEC07FFFD66AC95CE5*__this, ReadOnlyMemory_1_t43203E8B19A7F4A97A9A49363F67C206E8B058FE ___0_data, int32_t___ 1_conformanceMode, bool ___2_allowMultipleRootLevelValues, const RuntimeMethod* method) ;
> 
> ```
> 
> Where the method signature is `(ReadOnlyMemory<byte> data, CborConformanceMode conformanceMode = CborConformanceMode.Strict, bool allowMultipleRootLevelValues = false)`
> 
> There are a few other dead forum posts that have similar issues:  
> [https://discussions.unity.com/t/841721](https://discussions.unity.com/t/841721)  
> [https://discussions.unity.com/t/807279](https://discussions.unity.com/t/807279)
> 
> Any thoughts on how to resolve this or and potential fixes that can happen.
> 
> Using mono instead of IL2CPP has no issues

Does your [ICP.NET](http://ICP.NET) project include its own implementation of System.Memory.dll (maybe to support .NET Standard 2.0)? If so, Unity developers need to remove that, since Unity 2021 and later supports these types in its base class library implementation.

The error message here suggests to me that there are duplicates of those types, which often happens when a System.Memory.dll is included in the project.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gekctek/32/376090_2.png) [@Gekctek](https://discussions.unity.com/u/Gekctek)\
**Post date:** [April 10, 2023, 4:05pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/3 "2023-04-10T16:05:23Z")

</div>

> [@JoshPeterson](#):
>
> Does your [ICP.NET](http://ICP.NET) project include its own implementation of System.Memory.dll (maybe to support .NET Standard 2.0)? If so, Unity developers need to remove that, since Unity 2021 and later supports these types in its base class library implementation.
> 
> The error message here suggests to me that there are duplicates of those types, which often happens when a System.Memory.dll is included in the project.

I tried that with no luck. It has the same issue.  
From what I understand this a compile time conversion issue between IL and CPP using IL2CPP. It doesnt seem to like readonly structs or something

---

<div class="post-metadata">

**Author:** ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)\
**Post date:** [April 10, 2023, 4:06pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/4 "2023-04-10T16:06:49Z")

</div>

> [@Gekctek](#):
>
> I tried that with no luck. It has the same issue.  
> From what I understand this a compile time conversion issue between IL and CPP using IL2CPP. It doesnt seem to like readonly structs or something

Yes, this does sound like it is a bug on the IL2CPP side then. Can you submit a bug report for this issue? We would love to investigate it more.

[https://unity.com/releases/editor/qa/bug-reporting](https://unity.com/releases/editor/qa/bug-reporting)

---

<div class="post-metadata">

**Author:** ![Gekctek](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gekctek/32/376090_2.png) [@Gekctek](https://discussions.unity.com/u/Gekctek)\
**Post date:** [April 10, 2023, 11:18pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/5 "2023-04-10T23:18:58Z")

</div>

Done. Thank you

---

<div class="post-metadata">

**Author:** ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)\
**Post date:** [April 11, 2023, 11:49am UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/6 "2023-04-11T11:49:37Z")

</div>

> [@Gekctek](#):
>
> Done. Thank you

Can you let me know the bug number? Then I can track it down in our system.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gekctek/32/376090_2.png) [@Gekctek](https://discussions.unity.com/u/Gekctek)\
**Post date:** [April 11, 2023, 3:39pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/7 "2023-04-11T15:39:45Z")

</div>

> [@JoshPeterson](#):
>
> Can you let me know the bug number? Then I can track it down in our system.

CASE IN-37985

---

<div class="post-metadata">

**Author:** ![admoraguilar](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@admoraguilar](https://discussions.unity.com/u/admoraguilar)\
**Post date:** [April 15, 2023, 10:49am UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/8 "2023-04-15T10:49:03Z")

</div>

Hello, seems like my issue is the same. I’ve been trying to use ImageSharp in Unity 2022.2.14. [GitHub - SixLabors/ImageSharp at release/1.0.x](https://github.com/SixLabors/ImageSharp/tree/release/1.0.x)

All is good in the editor but it always fails on WebGL:

 ![8950893--1228854--Screenshot 2023-04-15 184406.png](https://europe1.discourse-cdn.com/unity/original/4X/2/6/d/26dedb0c8f8ecdf29595790ac7ba5e75e6508b4e.png)

Eventually managed to track it down this line after days of debugging.

 ![8950893--1228857--Screenshot 2023-04-15 183849.png](https://europe1.discourse-cdn.com/unity/original/4X/9/b/3/9b3c6f668d6de7f0644667c1e30da059273dac76.png)

So signature eventually becomes `this.EncodePixelRow<Rgb32>(ReadonlySpan<Rgb32>, IndexedImageFrame<Rgb32>, int)`.

Seems like it was fixed for ReadOnlySpan\<\> fields.

> [@Il2Cpp ReadOnlySpan feilds crash](https://discussions.unity.com/t/894872):
>
> Hey! We need help from somebody who knows the details about changes in ReadOnlySpan =\> new byte[&nbsp;] pattern in il2cpp in recent unity versions. After upgrading to a new unity version (from 2021.3.2 to 2021.3.9 and then to 2022.1.16f1) we are seeing a crash in the Global Metadata CPP file when getting these ReadOnlySpan fields. Here is the full callstack for windows platform: The build was compiled with minimal stripping. When we use the debug version of il2cpp we see the error that the fieldR…

Do we have a timeline for a fix if this has been already reproduced? Thanks!

---

<div class="post-metadata">

**Author:** ![admoraguilar](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@admoraguilar](https://discussions.unity.com/u/admoraguilar)\
**Post date:** [April 15, 2023, 12:45pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/9 "2023-04-15T12:45:14Z")

</div>

Just now I’ve done a test and I’ve replaced the ReadOnlySpan method parameters to TPixel[&nbsp;] and it worked. Anytime I’ll hit over a Span\<\> or ReadOnlySpan\<\> method parameter I’m having “null function or function signature mismatch”. So I think we can add this note to your investigation.

---

<div class="post-metadata">

**Author:** ![Gekctek](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/gekctek/32/376090_2.png) [@Gekctek](https://discussions.unity.com/u/Gekctek)\
**Post date:** [April 17, 2023, 3:34pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/10 "2023-04-17T15:34:34Z")

</div>

I have a bug report in with Unity but it has not been reproduced at this point. Hopefully today we’ll see something

---

<div class="post-metadata">

**Author:** ![elephant500](https://avatars.discourse-cdn.com/v4/letter/e/858c86/32.png) [@elephant500](https://discussions.unity.com/u/elephant500)\
**Post date:** [April 26, 2023, 7:00am UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/11 "2023-04-26T07:00:44Z")

</div>

@JoshPeterson is there any update on the status of this fix?

We’re currently blocked from doing a major game release due to this bug.

---

<div class="post-metadata">

**Author:** ![JoshPeterson](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/joshpeterson/32/44179_2.png) [@JoshPeterson](https://discussions.unity.com/u/JoshPeterson)\
**Post date:** [April 26, 2023, 4:12pm UTC](https://discussions.unity.com/t/il2cpp-doesnt-support-readonlymemory-t-or-readonlyspan-byte-method-parameters/914544/12 "2023-04-26T16:12:17Z")

</div>

> [@atomikm](#):
>
> @JoshPeterson is there any update on the status of this fix?
> 
> We’re currently blocked from doing a major game release due to this bug.

It looks like our QA team is still working to reproduce it. I’ve just pinged them to try to expedite the process.
