Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Maui release build crashes but debug build is fine #18870

Closed
sachinkanadia opened this issue Nov 18, 2023 · 30 comments
Closed

.NET Maui release build crashes but debug build is fine #18870

sachinkanadia opened this issue Nov 18, 2023 · 30 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/iOS 🍎 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@sachinkanadia
Copy link

Description

Hello,

I have an app (LightWork) that I want to publish on the Apple App Store. The debug build runs and works fine, however, on submission the release build crashes on start up. The symbolicated crash report can be found here:

https://stackoverflow.com/questions/77495334/net-maui-release-build-crashes-but-debug-build-is-fine

I tried disabling XAML compilation & setting the same build configuration against the debug. So I can confirm I don't think it has anything to do with XAML or the build configuration.

I have no idea why its failing and its preventing release. If anyone can help that would be much appreciated.

Many Thanks!

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

7.0.100

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@sachinkanadia sachinkanadia added the t/bug Something isn't working label Nov 18, 2023
@drasticactions drasticactions added the s/needs-repro Attach a solution or code which reproduces the issue label Nov 19, 2023
@ghost
Copy link

ghost commented Nov 19, 2023

Hi @sachinkanadia. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@drasticactions
Copy link
Contributor

Without a repro project or a stack trace, this will most likely be impossible to debug. Would it be possible to create a project showing your issue, or a stack trace from the release build? @rolfbjarne Are there other things they could provide to help diagnose this?

@rolfbjarne
Copy link
Member

All the stack trace says is that there was an unhandled exception, but nothing about the exception itself.

As a wild guess, try enabling the interpreter to see if that makes a difference (it's enabled by default for Debug builds already; this would enable it for all builds):

<PropertyGroup>
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Nov 21, 2023
@ahoffmandevelopment
Copy link

I'm having the same issue with both local and Azure pipeline builds. Debug works fine but release crashes immediately on startup.

Things I've tried:

  • Setting UseInterpreter to True as described above.
  • Disabling the linker for release builds.
  • Linking with SdkOnly and leaving in NewsstandKit.

Also, possible related are issues #18652 and #18528 .

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Nov 22, 2023
@rolfbjarne
Copy link
Member

Can you attach your csproj?

@ahoffmandevelopment
Copy link

ahoffmandevelopment commented Nov 27, 2023

Unfortunately, I cannot. However, since it's working in Debug but not Release, I changed my Debug build to Link SdkOnly, and now I can see this error immediately upon startup:

2023-11-27 10:57:51.668 XXXX[454:7918] Unhandled managed exception: Could not resolve type with token 01000007 from typeref (expected class 'System.Reflection.AssemblyDefaultAliasAttribute' in assembly 'System.Private.CoreLib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e') (System.TypeLoadException)
   at System.Reflection.CustomAttribute.GetCustomAttributesBase(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.CustomAttribute.GetCustomAttributes(ICustomAttributeProvider , Type , Boolean )
   at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type , Boolean )
   at Microsoft.Maui.Platform.ReflectionExtensions.GetCustomAttributesSafe(Assembly assembly, Type attrType)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Assembly[] assemblies, Assembly defaultRendererAssembly, Type[] attrTypes, InitializationFlags flags, Action`1 viewRegistered, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Type[] attrTypes, InitializationFlags flags, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Internals.Registrar.RegisterAll(Type[] attrTypes, IFontRegistrar fontRegistrar)
   at Microsoft.Maui.Controls.Compatibility.Forms.RegisterCompatRenderers(IMauiContext )
   at Microsoft.Maui.Controls.Compatibility.Forms.SetupInit(IMauiContext , Nullable`1 )
   at Microsoft.Maui.Controls.Compatibility.Forms.Init(IActivationState , Nullable`1 )
   at Microsoft.Maui.Controls.Compatibility.Hosting.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__1_1(IMauiContext )
   at Microsoft.Maui.Platform.ApplicationExtensions.<>c__DisplayClass3_0.<CreatePlatformWindow>b__0(OnMauiContextCreated del)
   at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnMauiContextCreated](IServiceProvider services, Action`1 action)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
   at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
   at UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
   at UIKit.UIApplication.Main(String[] , Type , Type )
   at XXXXXX.Program.Main(String[] args) in /Users/XXXX/Projects/XXXX/XXXXPlatforms/iOS/Program.cs:line 13

@ahoffmandevelopment
Copy link

So my issue ended up being with a library that I had recently brought in, TinyMapper. While I could have probably taken the time to figure out what was being linked out, I just removed the library and refactored my code, and now release builds are running correctly in Azure.

@sachinkanadia
Copy link
Author

Not the same here.

@rolfbjarne I tried enabling the interpreter but I got the same crash with the same stack trace.

@rolfbjarne
Copy link
Member

Does disabling the linker help?

<PropertyGroup>
    <MtouchLink>None</MtouchLink>
    <UseInterpreter>true</UseInterpreter>
</PropertyGroup>

@sachinkanadia
Copy link
Author

@rolfbjarne it still fails but I think it produces a different log which I've attached. The IPS file is not symbolicated as I can't seem to find it in the organizer in XCode.

Crash.zip

@rolfbjarne
Copy link
Member

Can you try disabling symbol stripping to see if that makes the crash report more useful?

<PropertyGroup>
    <MtouchLink>None</MtouchLink>
    <UseInterpreter>true</UseInterpreter>
    <NoSymbolStrip>true</NoSymbolStrip>
</PropertyGroup>

@sachinkanadia
Copy link
Author

LightWork-2023-11-28-162617.txt
Doesn't add symbols with the NoSymbolStrip enabled. Be sure to rename the file to ".ips".

@rolfbjarne
Copy link
Member

That didn't clarify much :/

Are you able to reproduce locally by building the Release configuration (as opposed to having to publish the app first)?

@sachinkanadia-se
Copy link

I am currently building and deploying locally to my physical iOS device. I am setting the release profile and certificate to development. As its release build it doesn't debug, but it does deploy. When I run the deployed app it just crashes immediately and this is without any debugger attached so I can't see any exception raised in VS.

@rolfbjarne
Copy link
Member

Can you get a binlog for a working Debug build and a failing Release build and attach them here? That should make it possible to see the differences in the build configuration that causes this.

@sachinkanadia
Copy link
Author

I now get this log when running the app but the iOS App still crashes on release mode.

Screenshot 2024-03-03 at 13 18 25

I'm quite sure the distribution certificate and profile are fine. Any ideas?

@rolfbjarne
Copy link
Member

@sachinkanadia can you disable stripping of native symbols, try again, and see if the resulting stack trace is more descriptive?

Just add this to the project file:

<PropertyGroup>
    <NoSymbolStrip>true</NoSymbolStrip>
</PropertyGroup>

@sachinkanadia
Copy link
Author

I did as you mentioned and it produced this crash log.

Screenshot 2024-03-04 at 19 32 30

This is annoying. Why does it crash without any info on the exception?

@rolfbjarne
Copy link
Member

It looks like the symbols were still stripped. Did you clean your project after changing the project file? If cleaning doesn't change anything, please get a binary build log (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs) and attach it here, which should explain why the symbols are still stripped.

This is annoying. Why does it crash without any info on the exception?

Because iOS doesn't let us add anything to the crash report. Third-party crash reporters typically collect more information about fatal exceptions. Additionally, more information will be printed to the device log (https://support.apple.com/en-in/guide/console/cnsl1012/mac).

@sachinkanadia
Copy link
Author

I cleaned the project and rebuilt the project. Still, the same stack trace persists.

@rolfbjarne
Copy link
Member

If cleaning doesn't change anything, please get a binary build log (Wiki: Diagnosis (binary build logs) (xamarin/xamarin-macios)) and attach it here, which should explain why the symbols are still stripped.

@sachinkanadia
Copy link
Author

sachinkanadia commented Mar 24, 2024

Screenshot 2024-03-24 at 16 13 03

@rolfbjarne My extensions manager is not showing any extensions. I am running VS Mac 17.6.10 (build 428). Is there a source that I need to add? Or do you have a link to Project System Tools for Mac that I can download?

@rolfbjarne
Copy link
Member

@sachinkanadia no idea, I've never seen that before. And since VSMac is going out of support in a few months, I don't think any issues will be fixed. My recommendation would be to either try building from the command line and getting a binlog that way (which is much easier), or use VSCode.

@sachinkanadia
Copy link
Author

@rolfbjarne Wouldn't I still need to download the Project System Tools for Mac to build from the command line in order to obtain the binlog? Also would you be able to point me to the instructions for building from the command line, please? Thanks

@rolfbjarne
Copy link
Member

@sachinkanadia
Copy link
Author

sachinkanadia commented Apr 1, 2024

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
	  <CreatePackage>false</CreatePackage>
	  <MtouchEnableSGenConc>true</MtouchEnableSGenConc>
	  <CodesignProvision>LightWork</CodesignProvision>
	  <CodesignKey>iPhone Distribution: sachin kanadia (EVLL97WB58)</CodesignKey>
	  <MtouchLink>SdkOnly</MtouchLink>
	  <MtouchFloat32>true</MtouchFloat32>
	  <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
	  <NoSymbolStrip>true</NoSymbolStrip>
	</PropertyGroup>

@rolfbjarne The above build configuration has produced the following build log output when executing:

dotnet publish -f net8.0-ios -p:ArchiveOnBuild=true -bl:publish.binlog

publish.binlog.zip

Please let me know what you find, (Why it is stripping debug symbols which hides the runtime exception) many thanks.

@sachinkanadia
Copy link
Author

Hey @rolfbjarne have you had a chance to look at this? Thanks

@rolfbjarne
Copy link
Member

Hey @rolfbjarne have you had a chance to look at this? Thanks

Sorry for the late reply, I've been away.

Please let me know what you find, (Why it is stripping debug symbols which hides the runtime exception) many thanks.

Unfortunately that revealed that the symbols are not stripped away, so I have no idea why the crash report is so useless.

However, can you try getting the device log (https://support.apple.com/en-in/guide/console/cnsl1012/mac) and see if it says something useful?

@sachinkanadia
Copy link
Author

sachinkanadia commented Apr 7, 2024

I see this error in the device log against my App:

Unhandled managed exception: Attempting to JIT compile method '(wrapper dynamic-method) LightWork.Entities.Exercise object:Thunk1ret_Exercise_QueryContext_DbDataReader_ResultContext_SingleQueryResultCoordinator (System.Func2<object[], object>,Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,Microsoft.EntityFrameworkCore.Query.Internal.ResultContext,Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryResultCoordinator)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information. (System.ExecutionEngineException) at System.Delegate.CreateDelegate(Type , Object , MethodInfo , Boolean , Boolean ) at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type , Object ) at System.Dynamic.Utils.DelegateHelpers.CreateObjectArrayDelegateRefEmit(Type , Func2 )
at System.Dynamic.Utils.DelegateHelpers.CreateObjectArrayDelegate(Type , Func`2 )
at System.Linq.Expressions.Interpreter.LightLambda.MakeDelega<…>

The question is do you think this is causing the App to crash?
If so I need to track down the method which is causing the issue as the documentation mentions:

Using Delegates to call Native Functions
To call a native function through a C# delegate, the delegate's declaration must be decorated with one of the following attributes:

[UnmanagedFunctionPointerAttribute](preferred, since it is cross-platform and compatible with .NET Standard 1.1+)
[MonoNativeFunctionWrapperAttribute]

Source: https://learn.microsoft.com/en-gb/xamarin/ios/internals/limitations

@sachinkanadia
Copy link
Author

Aha! It's solved!

I stumbled upon this article: #9176

Which helped me get to the solution.

I had to enable the interpreter and delete the obj and bin folders before building in Release mode.

Thanks @rolfbjarne your help has been imperative!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/iOS 🍎 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants