Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Xamarin IOS Linking #929

Closed
Gevand opened this issue Apr 13, 2020 · 9 comments
Closed

Xamarin IOS Linking #929

Gevand opened this issue Apr 13, 2020 · 9 comments

Comments

@Gevand
Copy link

Gevand commented Apr 13, 2020

Answer
Figured this out with our team and were able to upload to apple. Adding --nolinkaway to aditional mtouch parameters solved the issue. For some reason it seems to needs to be first if --optimize parameter is passed in.

image

Question
I'm having trouble setting up linking for the sample Xamarin app in this repository. In order to submit to apple, Microsoft suggests to set up the iOS build to have "link framework sdks only". Otherwise the app will exceed Apple's 60mb limit. CSLA should be skipped with those settings and function normally.

Here are my settings.

image

When clicking on the add button in the sample app, and invoking a dataportal for the first time an error occurs.

image

I get the following error:

image

I googled around and tried different mtouch parameters such as --nolinkaway and --linkskiping CSLA libraries and the Link ALL option.

Does anyone here have an app published to the app store that uses Xamarin + CSLA and if so, what parameters did you use for iOS linker behavior.

I'm gonna keep working on this, and if I figure it out, I'll append something to this post.

Version and Platform
CSLA version: 5.1.0-R19110101
OS: iOS,
Platform: Xamarin

@rockfordlhotka
Copy link
Member

I don't know a solution here. But I can provide some insight into what is probably happening.

The data portal dynamically invokes various methods, and those methods are often private. For example:

  • DataPortal_XYZ
  • AddObjectBusinessRules

Those methods would appear, to any static code analysis, to be "dead code" - never called by anything, because they are called dynamically. As a result, the linker (which applies static analysis) almost certainly removes those methods to reduce the binary output size.

Of course at runtime those methods literally aren't there anymore and so attempting to invoke them results in a linked away exception. Which is pretty polite really - it means that the linker replaced the methods with a little stub that throws a "friendly" exception.

It is generally less important that you prevent Csla.dll from linking. It is your business library assembly that is dynamically invoked.

There are a few cases where CSLA will dynamically invoke non-public methods in base classes (like the DataPortal_Create method in BusinessBase - but those are fallbacks and you can work around them being eliminated by always implementing those methods in your business class, rather than letting the fallback behavior occur).

@rockfordlhotka
Copy link
Member

Although it is hard (for me at least) to follow twitter threads, I started a thread about linker issues late last night actually, because I ran into one when dealing with client-side Blazor. The thread has some interesting insights into managing the linker from the Uno Platform team, because they sit on the same infrastructure as Xamarin (and also on wasm) and so have intimate understanding of the linker.

https://twitter.com/RockyLhotka/status/1249545555266752512?s=20

@Gevand
Copy link
Author

Gevand commented Apr 13, 2020

Thank you for the prompt response. I understand what you mean about public methods. When using static code analysers, we've dealt with that on our team when running apps through SonarQube.

However I don't believe this is the exact problem.

When selecting the "Link framework SDKs only", linking is done only to the .NET libraries like Xamarin.IOS and Xamarin.Essentials. As a third party library, CSLA should be untouched. However there must be something that CSLA relies upon that is being stripped out of these framework SDKs, because the linker can't see that CSLA is using that functionality.

When it comes to the sample project adding a --nolinkaway parameter makes the error go away.
image

However I cannot make the error go away on our production ready app. Which I'm working on right now. If I figure anything out I'll add a reply to this thread.

@Chicagoan2016
Copy link

@brinawebb , I voted yes because I thought making those methods public would help solve this issue @Gevand is talking about here.

@brinawebb
Copy link

Sorry, I replied to the wrong thread.

@Chicagoan2016
Copy link

@Gevand , If I may add a question here.
Has anyone of us published a Csla based iOS app to the App store?
kind regards

@Gevand
Copy link
Author

Gevand commented Apr 14, 2020

@Gevand , If I may add a question here.
Has anyone of us published a Csla based iOS app to the App store?
kind regards

Our team is planning on doing that in October. The apps viewmodels are inheriting from CSLA. We are submitting to apple the first few features ahead of time, to make sure nothing bites us. Currently still working on the submission process. Once we figure everything out, I'll dump all the knowledge to my original post.

@Chicagoan2016
Copy link

@Gevand thank you , will be eagerly waiting.
Regards

@Gevand
Copy link
Author

Gevand commented Apr 24, 2020

We figured out the issue. I appended the answer to the question.

@Gevand Gevand closed this as completed Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants