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 iOS project crashes #3171

Closed
trevortirrell opened this issue May 5, 2022 · 17 comments
Closed

.Net Maui iOS project crashes #3171

trevortirrell opened this issue May 5, 2022 · 17 comments

Comments

@trevortirrell
Copy link

Describe the bug
My .Net Maui iOS app crashes when navigating to the code that uses the Microsoft.Azure.Cosmos package. It works great with Android. Should I try the Azure.Cosmos 4.0.0-preview3?

To Reproduce
Add Microsoft.Azure.Cosmos package to project. iOS crashes on this line FeedResponse<MyObject> currentResultSet = await queryResultSetIterator.ReadNextAsync();

I'm only able to build from command line (.Net Maui issue). I'm using the following parameter /p:EnableAssemblyILStripping=false. I've also tried /p:MtouchLink=none for the Linker Behavior. Not sure if there is some other flag I need?

Expected behavior
Retrieve data from Azure Cosmos database

Actual behavior
App crashes

Environment summary
.Net Maui RC2
Visual Studio: 17.2 Preview 6
SDK Version: 3.26.1
OS Version: iOS 15.4.1

@ealsur
Copy link
Member

ealsur commented May 5, 2022

Please do not use 4.0.0 for production applications.

What is the error you are getting? Also, why are you running the SDK in a client device? That poses a security risk, ideally the architecture should look like: https://docs.microsoft.com/en-in/azure/architecture/solution-ideas/articles/gaming-using-cosmos-db

@trevortirrell
Copy link
Author

Please do not use 4.0.0 for production applications.

What is the error you are getting? Also, why are you running the SDK in a client device? That poses a security risk, ideally the architecture should look like: https://docs.microsoft.com/en-in/azure/architecture/solution-ideas/articles/gaming-using-cosmos-db

It works fine in Debug. But crashes in Release. So, no error. I'm still trying to troubleshoot. I'll upload my sample code in a few minutes.

@trevortirrell
Copy link
Author

I'm still unsuccessful at getting Microsoft.Azure.Cosmos to work with iOS in Release mode. Works just fine in Debug. This is the error I'm getting.

C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.300-rc.3.83\targets\Xamarin.Shared.Sdk.targets(747,3): error : ILStrip failed for C:/Users/ttirr/.nuget/packages/microsoft.azure.
cosmos/3.27.0/runtimes/win-x64/native/Microsoft.Azure.Cosmos.ServiceInterop.dll: The image is not a managed assembly [C:\Repos\MakerBreaker\MakerBreaker\MakerBreaker.csproj]

@trevortirrell
Copy link
Author

... why are you running the SDK in a client device? That poses a security risk, ideally the architecture should look like: https://docs.microsoft.com/en-in/azure/architecture/solution-ideas/articles/gaming-using-cosmos-db

I'm using Microsoft documentation (See links below). I have used it successfully in Xamarin.Forms apps in the past. Just won't work with .Net Maui.
https://docs.microsoft.com/en-us/azure/cosmos-db/sql/sql-api-get-started
https://www.youtube.com/watch?v=R_Fi59j6BMo

The link you gave me seems more complex that what I need.

@ealsur
Copy link
Member

ealsur commented May 23, 2022

@trevortirrell The gist of the other link (while complex) tries to show that for Mobile applications, the ideal architecture is having the SDK running in a Web API/service and the mobile devices contacting this Web API/service. Don't create the mobile application that talks to the Cosmos DB endpoint, because you are baking your account key inside a mobile application that can be decompiled. Once a user decompiles the app, it has your account master key. That is why running the SDKs in a mobile application is not a desirable scenario.

@trevortirrell
Copy link
Author

@ealsur Is there a walkthrough / tutorial that shows how to get that to work? For my current application it is only used for a leader board with scores, I don't care about security for this particular app.

And regardless it doesn't answer the question as to why it wont compile. That is still an issue that needs addressed / fixed.

@ealsur
Copy link
Member

ealsur commented May 23, 2022

I am not sure there is a full example. Any Web API example would show how to have the SDK running in a Web App, but the whole flow, I don't know. There is a Web API example here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql/sql-api-dotnet-application

Even on a leader board, the user has access to your master key, they can do anything on the account, including taking over your collections, reading all your data, even use your account and create a 1M RU collection there and hit you with a huge bill. It is a very scary scenario that you really don't want to have.

I am not a NET Maui expert, so I would not know why it won't compile, what we can say though is that it's not an environment or scenario where it is designed to run.

@ealsur
Copy link
Member

ealsur commented Jun 7, 2022

Closing due to inactivity. Please share more information in case this is still an issue.

@ealsur ealsur closed this as completed Jun 7, 2022
@RCGame
Copy link

RCGame commented Jun 11, 2023

ealsur is right. It's very risky someone could hijack your entire container. It would be too late to feel sorry when you receive a massive bill from microsoft. Azure web api service is very easy to setup for a simple scenario like yours.
You can hit a button to create a single read/write endpoint instead of a controller.

public static class LeaderboardEndpoints

{
    public static void MapLeaderboardEndpoints(this IEndpointRouteBuilder routes)
    {
        routes.MapPost("/api/LeaderboardUser", async ([FromBody] LeaderboardUser model) =>
        {
            var rsp = await CosmosDBHelper.RegisterLeaderboardUser(model);
            return rsp;
        })
        .WithName("CreateLeaderboardUser");
    }
}

Put your CosmosDB code inside CosmosDBHelper.RegisterLeaderboardUser(model);

From client device :

public class RestfulApi

{
    public static async Task<LeaderboardUser> RegisterLeaderboardUser(LeaderboardUser model)
    {
        HttpClient client = new HttpClient();
        var rsp = await client.PostAsJsonAsync<LeaderboardUser>("https://yourdomain.azurewebsites.net/api/LeaderboardUser", model);
        if (rsp.IsSuccessStatusCode)
        {
            var model = await rsp.Content.ReadFromJsonAsync<LeaderboardUser>();
            return model;
        }
        return null;
    }
}

@mdbill
Copy link

mdbill commented Apr 4, 2024

I'm still unsuccessful at getting Microsoft.Azure.Cosmos to work with iOS in Release mode. Works just fine in Debug. This is the error I'm getting.

C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.300-rc.3.83\targets\Xamarin.Shared.Sdk.targets(747,3): error : ILStrip failed for C:/Users/ttirr/.nuget/packages/microsoft.azure. cosmos/3.27.0/runtimes/win-x64/native/Microsoft.Azure.Cosmos.ServiceInterop.dll: The image is not a managed assembly [C:\Repos\MakerBreaker\MakerBreaker\MakerBreaker.csproj]

Other than I'm on 3.38.1 (vs 3.27.0),
I have this exact error trying to bundle the .ipa for the app store. The app doesn't crash, it just won't build. Everything works in Windows, & Android. With iOS, the simulator works. Without telling me to change my architecture, please help me get past this.
If I "false", then I get some aot- errors. I also tried various linking strategies and "true"

Also note: This has been working in production for 4 years with Xamarin.Forms. I'm just trying to upgrade to MAUI.

This is a windows-only dll, but 3 1/2 years ago, I was told...

Is the ServiceInterop.dll being included? The SDK assumes that the dll is always available even if it is not on a supported platform.

ServiceInteropWrapper.AssembliesExist = new Lazy<bool>(() => true);

@ealsur
Copy link
Member

ealsur commented Apr 4, 2024

If you don't bundle the Microsoft.Azure.Cosmos.ServiceInterop.dll as part of your app, the SDK will still work.

However, please see #3171 (comment) for security issues related to running the SDK within the app.

@mdbill
Copy link

mdbill commented Apr 4, 2024

If you don't bundle the Microsoft.Azure.Cosmos.ServiceInterop.dll as part of your app, the SDK will still work.

Thanks for the quick reply!
That's encouraging, but how do I accomplish this? I'm unable to build the ipa bundle and I've tried a couple dozen different ways to attempt to get around the error I mentioned.

@ealsur
Copy link
Member

ealsur commented Apr 5, 2024

I honestly have no expertise in what an ipa module is. But if the build process generates a package and there is a way to remove/ignore a DLL into getting added to the package, you could ignore / skip this one.

@mdbill
Copy link

mdbill commented Apr 5, 2024

Any idea where this dependency gets introduced? Maybe I can just fork and rebuild cosmos without bringing this dll in? I'm no expert on .csproj files and building either. But don't you think the cosmos team should address this if people can't even build and run the Maui template app (with cosmosdb added) on iOS? probably not MacOS either.

@ealsur
Copy link
Member

ealsur commented Apr 5, 2024

This DLL has always been there.

@mdbill
Copy link

mdbill commented Apr 5, 2024

Yeah, it's always been there, but it worked with Xamarin.forms, so I guess I'm in the wrong place? The MAUI team should address this? Thanks for your help.

@ealsur
Copy link
Member

ealsur commented Apr 5, 2024

The MAUI team should address this?

I guess? I mean, it's not a change that happened in this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants