1

I have a weird problem. I created a .NET MAUI app. At a point of my app, i am loading some basic old .NET assemblies that i load into a byte array before, such as;

byte[] asmbinary=loadassemblybinary();
Assembly MyAssembly = Assembly.Load(asmbinary);

It runs perfect on

  • WinUI (both Debug and Release Mode),

  • Android (both Debug and Release modes),

  • MacCatalyst (both Debug and Release modes),

  • iOS (Debug mode)

but at iOS Release Mode, app crashes at Assembly.Load with no exception (even i can't catch it with try) .

Actually i dont need release mode, but I have some CollectionViews in my app. CollectionView scroll performance is really bad at debug modes but works smooth at release mode for all platforms. (i couldn't figure out why ui has such a low performance on debug mode, or how to fix it. A workaround for this would be good also)

Now i need to either speedup ui performance at debug mode, or fix Assembly.Load at iOS release mode.

Any idea for my situation?

Thanks in advance.

Ender

Ender KARADAG
  • 87
  • 2
  • 11
  • Do you have the correct Provisioning and Certs? If yes have you checked the build logs? Can you go to your project file and see if are there any differences b/w your debug and release configs, All these things would help debug this! – FreakyAli Mar 02 '23 at 02:49
  • Thanks for your comment. Yes, i did. Provisioning Profiles are correct (so app starts successfully at the device with release mode) Nothing unexpectad at build logs. And checked differences between debug and release modes, linker behavior, optimizations etc. All same. At debug mode, even changing app from portrait to landscape freezes for a second. but at release mode ui is so smooth. i couldn't figure out what causes debug mode to lower ui performance – Ender KARADAG Mar 02 '23 at 03:00
  • Debug always has lower performance than the release version, usually because linking is set to none and runtime code changes, Anyway can you search exceptions in build logs – FreakyAli Mar 02 '23 at 03:05
  • Release mode build logs seem to be the same with debug mode build logs. But i will recheck it from the start. Any idea to catch what is going on in the device when app crashes? – Ender KARADAG Mar 02 '23 at 03:17
  • Well one thing you could do to get the StackTrace would be to add a TryCatch on the last line of code where you still have control, And see where it takes you in terms of Stacktrace, That would be a good starting point – FreakyAli Mar 02 '23 at 03:22
  • iOS will not allow you to dynamically load code at runtime. And im not clear what that has to do with UI performance – Jason Mar 02 '23 at 03:28
  • @Jason but i can load assembly at iOS debug mode – Ender KARADAG Mar 02 '23 at 03:30
  • @FreakyAli i catched the control at last line before crash, but nothing different comparing to debug mode – Ender KARADAG Mar 02 '23 at 03:31
  • Your Exception has no StackTrace? – FreakyAli Mar 02 '23 at 03:54

2 Answers2

0

CollectionView scroll performance is really bad at debug modes but works smooth at release mode for all platforms

tl;dr Test without an attached debugger. Either run w/o debugger, or after downloading, swipe kill, and run again from device's (or simulators) Home Screen.

Technically, most slow downs occur due to having an attached debugger. (Not to running in Release vs Debug.)

When a debugger is present, JIT optimization is disabled.
REASON: So that when a breakpoint is hit, or an exception is thrown, visual studio can accurately stop at the correct line.


The debug mode slowdown might be revealing a problem that you really should fix, to have smooth performance on lower end devices.

If you want to investigate this possibility, please create a new question, explain the situation (slowdown in debug), and include the xaml of your listview's itemtemplate.


Its also possible that it isn't the UI itself, but code that runs when items are displayed. Does each item in listview ItemTemplate contain an image? Or anything else that might take significant processing to fetch or to display?

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
0

i couldn't figure out why ui has such a low performance on debug mode, or how to fix it. A workaround for this would be good also

A similar problem has been posted on Q&A, you can add the following code to MauiProgram to try to solve it:

using Microsoft.Maui.Platform;// namespace

#if IOS   // add handler in MauiProgram.cs   
Microsoft.Maui.Handlers.ScrollViewHandler.Mapper.AppendToMapping("custom", (handler,view) =>        {           
 handler.PlatformView.UpdateContentSize(handler.VirtualView.ContentSize);            
 handler.PlatformArrange(handler.PlatformView.Frame.ToRectangle());       
 });
#endif

For more, you can refer to the Q&A issue:MAUI - CollectionView and scrolling - not working with IOS emulators

Update: In Release mode, because the compiler optimizes and compresses the code more, some dependencies may not be correctly referenced. You can check your project for missing dependencies and make sure they are properly referenced.

Attempt to load the assembly using the Assembly.LoadFile() method. This method can load an assembly from a specified file path instead of from a byte array.

Zack
  • 1,255
  • 1
  • 2
  • 5