Cannot find suitable method System.Enum.Parse(2 parameters) #4115
-
Seen in the wild at ppy/osu#20614 (this app is using Seems to be caused by trimming/optimization that is done on Android Release builds. Version: 12.0.0Expected behaviorUsing AutoMapper shouldn't crash the app. Actual behaviorUsing any part of AutoMapper crashes the app with the following stack trace. 10-22 22:51:30.070 24694 24694 E AndroidRuntime: FATAL EXCEPTION: main
10-22 22:51:30.070 24694 24694 E AndroidRuntime: Process: com.companyname.app1, PID: 24694
10-22 22:51:30.070 24694 24694 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'AutoMapper.Internal.Mappers.StringToEnumMapper' threw an exception. ---> System.ArgumentOutOfRangeException: Cannot find suitable method System.Enum.Parse(2 parameters).
10-22 22:51:30.070 24694 24694 E AndroidRuntime: Parameter name: methodName
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.Internal.TypeExtensions.StaticGenericMethod (System.Type type, System.String methodName, System.Int32 parametersCount) [0x0004e] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.Internal.Mappers.StringToEnumMapper..cctor () [0x00019] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: --- End of inner exception stack trace ---
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.Internal.Mappers.MapperRegistry.Mappers () [0x00049] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.MapperConfigurationExpression..ctor () [0x00040] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.MapperConfiguration.Build (System.Action`1[T] configure) [0x00000] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at AutoMapper.MapperConfiguration..ctor (System.Action`1[T] configure) [0x00000] in <f0f2d41eebaf41da82f0b54e1380e562>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at App1.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00022] in <9ca4390c120b485c93ba97c56d55de2c>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <95707276dab64377aff41df0eecbc657>:0
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr,intptr)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at crc64a7a6b04b89628087.MainActivity.n_onCreate(Native Method)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at crc64a7a6b04b89628087.MainActivity.onCreate(MainActivity.java:38)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8151)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8135)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3704)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3903)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2328)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.os.Looper.loop(Looper.java:255)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8212)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
10-22 22:51:30.070 24694 24694 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049) Steps to reproduce
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
+ var mapper = new AutoMapper.MapperConfiguration(c => { }).CreateMapper();
+ Title = mapper.ToString();
}
Steps to fix this issue (any will work)
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
+ var t = Enum.Parse<InputSourceType>("1", true);
+ Title = t.ToString();
var mapper = new AutoMapper.MapperConfiguration(c => { }).CreateMapper();
Title = mapper.ToString();
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
You need to configure your project to not trim the missing method. |
Beta Was this translation helpful? Give feedback.
-
I struggled with this in blazor for .net 7.0. The following is how i fixed it ... Project.csproj <ItemGroup>
<EmbeddedResource Include="./../ILLink.Descriptors.xml">
<LogicalName>ILLink.Descriptors.xml</LogicalName>
</EmbeddedResource>
</ItemGroup> ILLink.Descriptors.xml <linker>
<assembly fullname="AutoMapper" preserve="all" />
<assembly fullname="System.Runtime">
<type fullname="System.Enum" preserve="all" />
</assembly>
</linker> |
Beta Was this translation helpful? Give feedback.
You need to configure your project to not trim the missing method.