GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix for "System.NotImplementedException: byref delegate" by MaximMikhisor · Pull Request #1461 · MessagePack-CSharp/MessagePack-CSharp

Conversation

@MaximMikhisor

@MaximMikhisor MaximMikhisor commented Jun 28, 2022

Copy link
Copy Markdown
Contributor

Fix for "System.NotImplementedException: byref delegate" in System.Linq.Expressions for AOT compilation.
It is second attempt. First commit had accidently corrupted code lines.

See details here: #1344 (comment)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
maxim and others added 3 commits April 1, 2022 19:01
maxim maxim
Fix for "System.NotImplementedException: byref delegate" in System.Li…
c9fad94
…nq.Expressions for AOT compilation.
maxim maxim
Several lines of code were deleted (which were not deleted in previou…
7a4a9ef
…s commit by some unknown accident).
@MaximMikhisor
Merge pull request #1 from neuecc/master
8ef5aec
Merging
@MaximMikhisor MaximMikhisor mentioned this pull request Jun 28, 2022
Xamarin forms - iOS Deserialize throws System.NotImplementedException: byref delegate #1344
Closed
@MaximMikhisor MaximMikhisor changed the title Fix for "System.NotImplementedException: byref delegate" (asecond attempt) Fix for "System.NotImplementedException: byref delegate" (second attempt) Jun 28, 2022
gllebede-havok
gllebede-havok reviewed Jun 30, 2022
View reviewed changes
Comment thread src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializerOptions.cs Outdated

#if !DYNAMICCODEDUMPER
#if DYNAMICCODEDUMPER
static readonly MessagePackSerializerOptions _standard = new MessagePackSerializerOptions(Resolvers.BuiltinResolver.Instance);

@gllebede-havok gllebede-havok Jun 30, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This code fails on CI

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaximMikhisor MaximMikhisor Jun 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw it. Do you know why?
It builds ok on local PC.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gllebede-havok gllebede-havok Jul 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try something like
dotnet build --configuration Release /t:build,test,pack /m /v:m
from root folder of the repository. I've made a PR to your repository with couple fixes

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaximMikhisor MaximMikhisor Jul 3, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main goal to add code lines in this place is to have Standard MessagePackSerializerOptions when projects are build with DYNAMICCODEDUMPER symbol.

I am using this Standard static property for example to init MessagePack like this:

public static class MessagePackInitiator
{
	static Boolean _resolverWasRegistered = false;         

	public static void Run(MessagePackHubProtocolOptions options)
	{
		if (!_resolverWasRegistered)
		{
			StaticCompositeResolver.Instance.Register(
				GeneratedResolver.Instance,
				BuiltinResolver.Instance);

			_resolverWasRegistered = true;
		}           

		options.SerializerOptions = MessagePackSerializerOptions.Standard
			.WithResolver(StaticCompositeResolver.Instance)
			.WithSecurity(MessagePackSecurity.UntrustedData);
	}
	
}

But it appeared that it is not so easy to add this property here, because DynamicCodeDumper project has not some files.
Do not want to add missed files. Maybe MessagePack authours will do it.
Instead just deleted my changes.
And instead will init MessagePack like this in my code:

public static class MessagePackInitiator
{
	static Boolean _resolverWasRegistered = false;         

	public static void Run(MessagePackHubProtocolOptions options)
	{
		if (!_resolverWasRegistered)
		{
			StaticCompositeResolver.Instance.Register(
				GeneratedResolver.Instance,
				BuiltinResolver.Instance);

			_resolverWasRegistered = true;
		}           

		options.SerializerOptions =  new MessagePackSerializerOptions(Resolvers.BuiltinResolver.Instance)
			.WithResolver(StaticCompositeResolver.Instance)
			.WithSecurity(MessagePackSecurity.UntrustedData);
	}
	
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs Outdated
{
// public static void Serialize<T>(ref MessagePackWriter writer, T obj, MessagePackSerializerOptions options)
MethodInfo serialize = GetMethod(nameof(Serialize), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), null, typeof(MessagePackSerializerOptions) });
MethodInfo serialize = GetMethod(nameof(SerializeSemiGeneric), type, new Type[] { typeof(MessagePackWriter).MakeByRefType(), typeof(Object), typeof(MessagePackSerializerOptions) });

@gllebede-havok gllebede-havok Jun 30, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any performance penalty in SemiGeneric? Should it be only used under ENABLE_IL2CPP then, where is no other option?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaximMikhisor MaximMikhisor Jun 30, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view it should not be any perfomance penalty.
If you check SerializeSemiGeneric and DeserializeSemiGeneric methods -- they are just wrappers around current implementation with assitional casting. Do not think that casting will add any significatn penalty.

But I cannot garantee it.
Do you have any benchmarks? Can you compare two implementations?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gllebede-havok gllebede-havok Jul 1, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the delegate creates takes an object as command line argument anyway, so there is no penalty there. But calling Serialize/Deserialize now introduces unnecessary boxing for value types. Is it executed anywhere in a hot path and critical?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaximMikhisor MaximMikhisor Jul 3, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed a bit code.
Now SerializeSemiGeneric and DeserializeSemiGeneric are using only inside MessagePackSerializer.NonGeneric.cs file.
So it decreases cases where additional casting is using.

Do not know how methods from MessagePackSerializer.NonGeneric.cs are used in MessagePack (I am not MessagePack author).
So cannot answer on your question "Is it executed anywhere in a hot path and critical?"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@MaximMikhisor MaximMikhisor Jul 3, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: ENABLE_IL2CPP

I do not know what ENABLE_IL2CPP is for.
When this derective is using? What is advantages/disadvantages to use this option?
And I guess MessagePack nuget package will be build without this option, will not it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gllebede-havok gllebede-havok Jul 3, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ENABLE_IL2CPP is for Unity3D game engine where ahead of time compilation renders Emit code generation unusable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AArnott AArnott Jul 23, 2022

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think making the change only on unity wouldn't fix the original issue, which was an app running on iOS.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
maxim and others added 3 commits July 3, 2022 20:03
maxim maxim
Changes to fixx issues to pass CI build pipeline.
3cd5534
maxim maxim
Small bug fix
287c4f7
@AArnott
Revise the fix slightly
eb6b93b
AArnott
AArnott requested changes Jul 23, 2022
View reviewed changes

@AArnott AArnott left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge LineSmarts#3. Then I think we can take this. @neuecc should review as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/MessagePack.UnityClient/Assets/Scripts/MessagePack/MessagePackSerializer.NonGeneric.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/MessagePack.UnityClient/Assets/Scripts/MessagePack/Resolvers/DynamicObjectResolver.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@AArnott
AArnott requested a review from neuecc July 23, 2022 14:06
@MaximMikhisor
Merge pull request #3 from AArnott/pr1461
d75c56a
Revise the fix slightly
@MaximMikhisor

MaximMikhisor commented Jul 24, 2022

Copy link
Copy Markdown
Contributor Author

Please merge LineSmarts#3. Then I think we can take this. @neuecc should review as well.

Done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AArnott

AArnott commented Aug 2, 2022

Copy link
Copy Markdown
Collaborator

I introduced a new pair of non-generic perf tests to PerfBenchmarkDotNet (#1478) and measured before and after this change. The perf impact was negligible for serialize. The perf got a little slower and more noisy for deserialize, but I suspect it may be all noise.

For the tables below, focus on the IntKey_NonGeneric benchmark.

Before change

Method Job Toolchain IterationCount LaunchCount WarmupCount Mean Error StdDev Ratio RatioSD Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
IntKey InProcess InProcessToolchain Default Default Default 239.7 ns 2.575 ns 2.409 ns 1.00 0.00 0.0086 - - 56 B
IntKey_NonGeneric InProcess InProcessToolchain Default Default Default 256.3 ns 1.293 ns 1.080 ns 1.07 0.01 0.0086 - - 56 B

After change

Method Job Toolchain IterationCount LaunchCount WarmupCount Mean Error StdDev Ratio RatioSD Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
IntKey InProcess InProcessToolchain Default Default Default 242.9 ns 1.789 ns 1.585 ns 1.00 0.00 0.0086 - - 56 B
IntKey_NonGeneric InProcess InProcessToolchain Default Default Default 281.9 ns 5.782 ns 11.141 ns 1.19 0.05 0.0086 - - 56 B
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AArnott AArnott linked an issue Aug 2, 2022 that may be closed by this pull request
Xamarin forms - iOS Deserialize throws System.NotImplementedException: byref delegate #1344
Closed
AArnott
AArnott approved these changes Aug 2, 2022
View reviewed changes
@AArnott
AArnott merged commit 541ad7c into MessagePack-CSharp:master Aug 2, 2022
@AArnott AArnott changed the title Fix for "System.NotImplementedException: byref delegate" (second attempt) Fix for "System.NotImplementedException: byref delegate" Aug 3, 2022
@KazysNoobiys KazysNoobiys mentioned this pull request Oct 14, 2022
When will there be a new release? #1519
Closed
@dependabot dependabot Bot mentioned this pull request Sep 21, 2025
Bump MessagePack from 2.1.115 to 2.5.187 starchen/Brighter#4
Closed
This was referenced Oct 26, 2025
Bump MessagePack from 2.3.75 to 2.5.187 managedcode/umap#1
Closed
Bump MessagePack to 2.5.187 Senparc/Senparc.CO2NET#334
Merged
This was referenced Dec 2, 2025
Bump MessagePack from 2.3.85 to 3.1.4 dbolin/Apex.Serialization#262
Closed
Bump MessagePack and MessagePack.ImmutableCollection dbolin/Apex.Serialization#263
Open
@dependabot dependabot Bot mentioned this pull request Dec 10, 2025
Bump MessagePack from 1.9.11 to 2.5.187 dotnet/performance#5069
Open
@dependabot dependabot Bot mentioned this pull request Dec 26, 2025
Bump the nuget group with 2 updates niklasfp/nats.net#1
Closed
This was referenced Jan 22, 2026
Bump MessagePack from 2.4.59 to 2.5.187 collana-solutions/Csag.Extensions.Caching#3
Merged
Bump the nuget group with 1 update GlacierEQ/MemoryPack#1
Merged
@dependabot dependabot Bot mentioned this pull request Feb 20, 2026
Bump MessagePack from 2.3.85 to 3.1.4 Arkatufus/Akka.Persistence.Redis#82
Open
@dependabot dependabot Bot mentioned this pull request Mar 14, 2026
Bump the nuget group with 2 updates K1ko/osu#48
Open
This was referenced Jun 11, 2026
Bump MessagePack from 3.1.6 to 3.1.7 geekswagg/EFCoreSecondLevelCacheInterceptor#1
Closed
Bump MessagePack from 1.7.3.7 to 2.5.301 KikeE36/MasterMemory#1
Open
Bump the nuget group with 2 updates korgano/CustomAmmoCategories#1
Open
Bump the nuget group with 1 update IntelIntent/BinaryPack#1
Open
Bump MessagePack from 2.2.85 to 2.5.301 shahabganji/EasyCompressor#1
Open
Bump MessagePack from 1.9.11 to 2.5.301 shahabganji/SmartEnum#1
Open
Bump MessagePack from 2.3.85 to 2.5.301 gengle/MessagePipe#3
Closed
Bump the nuget group with 1 update pa-0/ahk.ucrio#1
Open
Bump MessagePack from 2.1.90 to 2.5.301 sniten/psi#2
Open
Bump the nuget group with 1 update abri-herdmaster/HerdMASTER.Dotmim.Sync#5
Open
Bump MessagePack from 2.1.90 to 2.5.301 Cysharp/Ulid#113
Open
Bump MessagePack from 2.2.113 to 2.5.301 x0oo11235oo0x/dotnet-algorand-sdk#1
Open
Bump MessagePack and System.Memory nmaier/NMaier.Serializers#1
Open
Bump MessagePack from 2.3.85 to 2.5.301 curiosity-ai/wiktionary#2
Open
Bump MessagePack from 2.1.115 to 2.5.301 generatives/VoidTraveler#1
Open
Bump MessagePack and System.Memory Philippe-Laval/catalyst#1
Open
Bump MessagePack from 2.1.115 to 2.5.301 starchen/Brighter#5
Open
Bump the nuget group with 1 update pawelkasperek/AlterNats#1
Open
Bump MessagePack from 1.9.11 to 2.5.301 ConnectionMaster/dd-trace-dotnet#788
Open
Bump MessagePack from 1.9.3 to 2.5.301 IllusionMods/ZipStudio#5
Merged
This was referenced Jun 26, 2026
Bump MessagePack from 2.3.112 to 2.5.301 nanoframework/nf-Visual-Studio-extension#936
Closed
Bump the nuget group with 3 updates infinispan/Infinispan.Hotrod.Core#56
Open
@dependabot dependabot Bot mentioned this pull request Sep 15, 2026
Bump MessagePack from 1.9.11 to 2.5.301 f2calv/vs-nuget-issue#1
Closed
This was referenced Oct 19, 2026
Bump MessagePack from 2.3.85 to 2.5.303 gengle/MessagePipe#4
Open
Bump the nuget group with 1 update aetos382/MemoryPack#1
Open
Bump MessagePack from 2.2.85 to 2.5.303 umbraco/Umbraco.Cms.Integrations#347
Open
Bump MessagePack from 2.3.112 to 2.5.303 nanoframework/nf-Visual-Studio-extension#956
Closed
Bump MessagePack to 2.5.303 Senparc/Senparc.CO2NET#347
Open
Bump the nuget group with 5 updates maximumstock/exilence-next#4
Open
@dependabot dependabot Bot mentioned this pull request Nov 7, 2026
Bump MessagePack from 1.7.3.4 to 2.5.303 automatica-core/automatica#136
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AArnott AArnott AArnott approved these changes
@neuecc neuecc Awaiting requested review from neuecc
+1 more reviewer
@gllebede-havok gllebede-havok gllebede-havok left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Xamarin forms - iOS Deserialize throws System.NotImplementedException: byref delegate

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@MaximMikhisor @AArnott @gllebede-havok
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.