Skip to content

Instantly share code, notes, and snippets.

@ivanpovazan
Created June 21, 2023 14:23
Show Gist options
  • Save ivanpovazan/27cc90887e9709f0bd46579f9987e996 to your computer and use it in GitHub Desktop.
Save ivanpovazan/27cc90887e9709f0bd46579f9987e996 to your computer and use it in GitHub Desktop.
HelloiOS sample patch including repro for runtime crash
diff --git a/src/mono/sample/iOS/Program.cs b/src/mono/sample/iOS/Program.cs
index 1c9839a8ae0..8f04eedd6db 100644
--- a/src/mono/sample/iOS/Program.cs
+++ b/src/mono/sample/iOS/Program.cs
@@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
+using System.Linq.Expressions;
public static class Program
{
@@ -30,18 +31,29 @@ public static async Task<int> Main(string[] args)
public static async Task Main(string[] args)
#endif
{
+ Console.WriteLine("Start!");
+
unsafe {
// Register a managed callback (will be called by UIButton, see main.m)
delegate* unmanaged<void> unmanagedPtr = &OnButtonClick;
ios_register_button_click(unmanagedPtr);
}
- const string msg = "Hello World!\n.NET 8.0";
- for (int i = 0; i < msg.Length; i++)
- {
- // a kind of an animation
- ios_set_text(msg.Substring(0, i + 1));
- await Task.Delay(100);
- }
+
+ string msg = "";
+
+ var item = new MyItem();
+ item.Id = 100;
+
+ try {
+ // msg = "hey";
+ msg = GetValue(item).ToString();
+ } catch(Exception e) {
+ msg = e.ToString();
+ }
+
+ Console.WriteLine(msg);
+ ios_set_text(msg);
+
Console.WriteLine("Done!");
#if CI_TEST
@@ -51,4 +63,32 @@ public static async Task Main(string[] args)
await Task.Delay(-1);
#endif
}
+
+ static object GetValue(object component) {
+ Func<object, object> propertyAccessorDelegate = CompileLambda();
+ return propertyAccessorDelegate(component);
+ }
+
+ static Func<object, object> CompileLambda() {
+ ParameterExpression parameter = Expression.Parameter(typeof(object), "p");
+ MemberExpression property = Expression.Property(Expression.Convert(parameter, typeof(MyItem)), "Id");
+ Expression<Func<object, object>> lambda = Expression.Lambda<Func<object, object>>(Expression.Convert(property, typeof(object)), parameter);
+ return lambda.Compile();
+ }
+}
+
+public class BaseItem {
+ int id;
+
+ public virtual int Id {
+ get => id;
+ set => this.id = value;
+ }
}
+
+public class MyItem: BaseItem {
+ int id;
+
+ //Some attributes....
+ public override int Id { get => base.Id; set => base.Id = value; }
+}
\ No newline at end of file
diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj
index 681d661fb44..2d5a42084be 100644
--- a/src/mono/sample/iOS/Program.csproj
+++ b/src/mono/sample/iOS/Program.csproj
@@ -25,6 +25,10 @@
<BuildAppBundleDependsOnTargets Condition="'$(ArchiveTests)' == 'true'">Publish</BuildAppBundleDependsOnTargets>
</PropertyGroup>
+ <ItemGroup>
+ <TrimmerRootAssembly Include="Program" />
+ </ItemGroup>
+
<Import Project="$(MonoProjectRoot)\msbuild\apple\build\AppleBuild.props" />
<Import Project="$(MonoProjectRoot)\msbuild\apple\build\AppleBuild.InTree.targets" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment