question

nnovalbos-6961 avatar image
0 Votes"
nnovalbos-6961 asked LeonLu-MSFT commented

Release error: System.InvalidProgramException

Hi,

I am getting errors when generating the release version of android.

The problem has come at the time of putting a searchbar to the project, for which I have followed the following tutorial:

https://codetraveler.io/2020/10/31/adding-a-search-bar-to-xamarin-forms-navigationpage/

In AppCenter I have caught 2 different errors, but it seems that it is the same:

error 1:

 System.InvalidProgramException
 System.InvalidProgramException: Invalid IL code in X.Core.ViewModels.MyViewModel: get_SearchedItems (): IL_0046: call 0x2b000212

error 2:

 SearchPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1 [TElement] e)
 System.InvalidProgramException: Invalid IL code in X.Droid.CustomRenders.SearchPageRenderer: AddSearchToToolbar (string): IL_0122: call 0x0a00421c

The property that the collection binds to is:

  public ObservableCollection <MyViewModel> SearchedItems => string.IsNullOrEmpty (SearchText)? MyViewModelsList:
             new ObservableCollection <MyViewModel> (MyViewModelsList.ToList (). Where (s =>! string.IsNullOrEmpty (s.Name) && s.Name.ToLower (). Contains (SearchText.ToLower ())));

Any ideas? On iOs it works correctly.

Thanks





dotnet-xamarin
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please release your application in the local environment, If it could release normally, If so, this issue is related to the AppCenter, you can get free support in this thread:https://docs.microsoft.com/en-us/appcenter/help#accessing-app-center-free-support

0 Votes 0 ·

Hi, @LeonLu-MSFT

The problem was not AppCenter, apparently the Android part does not like optionals (?):

 toolBar.Menu?.FindItem(Resource.Id.ActionSearch)?.ActionView?.JavaCast <SearchView> () .GetType ()! = typeof (SearchView))

Because it can be? Could it be because of the C # version? I have not touched anything and, in theory, I should use C# 8 (.net standard), but I have done tests I got the following message:

 "feature 'type pattern marching' cannot be used because it is not part of the C# 6.0"

How can I check the version that I am using in the Android project? How can I assign version 8?

Thank you.

0 Votes 0 ·

Please follow this thread to check the C# version:https://stackoverflow.com/a/63708835/10627299

1 Vote 1 ·

0 Answers