.NET Maui IOS Debug and Release mode difference

1.6k Views Asked by At

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

2

There are 2 best solutions below

0
On

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?

1
On

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.