msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Xamarin: make SDK linker-safe

Open tipa opened this issue 5 years ago • 3 comments

I am using this SDK in a Xamarin project and have full linking enabled. This results in classes from this library being linked away although needed, e.g. for deserializing JSON responses - which then of course results in an exception/app crash at runtime.

Of course I could exclude the whole library from the linking process but given the rather large SDK size (~4MB) I prefer not to. Right now I exclude the linked away classes manually from the linking process. However I saw that responses not always have all properties (and this even differs from user to user although the same code is being executed). So even when everything works for my OneDrive account, it is possible that my app users have different JSON responses and the classes for deserializing them arent included in the app.

It would be great if the SDK could be made linker-safe so that I wouldn't have to care and exclude classes manually. This can be done by Attributes as described here or here AB#7293

tipa avatar Jun 20 '19 18:06 tipa

Edit: For anyone that needs it, I was finally able to isolate what linker settings are required for OneDrive, though it could probably be even more specific:

<linker>
    <assembly fullname="Newtonsoft.Json">
        <type fullname="*" />
    </assembly>

    <assembly fullname="System.Text.Json">
        <type fullname="*" />
    </assembly>

    <assembly fullname="Microsoft.Graph">
        <type fullname="Microsoft.Graph.IDriveItemChildrenCollectionPage*" />
        <type fullname="Microsoft.Graph.DriveItemChildrenCollectionPage*" />
        <type fullname="Microsoft.Graph.DriveItem*" />
        <type fullname="Microsoft.Graph.BaseItem*" />
        <type fullname="Microsoft.Graph.Entity*" />
        <type fullname="Microsoft.Graph.Identity*" />
        <type fullname="Microsoft.Graph.IdentitySet*" />
        <type fullname="Microsoft.Graph.ItemReference*" />
        <type fullname="Microsoft.Graph.ICollectionPage*" />
        <type fullname="Microsoft.Graph.FileSystemInfo*" />
        <type fullname="Microsoft.Graph.Folder*" />
        <type fullname="Microsoft.Graph.File*" />
        <type fullname="Microsoft.Graph.FileSystemInfo*" />
        <type fullname="Microsoft.Graph.Hashes*" />
        <type fullname="Microsoft.Graph.UploadSession*" />
    </assembly>

    <assembly fullname="Microsoft.Graph.Core">
        <type fullname="*" />
    </assembly>

</linker>

kiddailey avatar May 19 '23 00:05 kiddailey

@maisarissi for thinking about this scenario.

ddyett avatar Jun 28 '23 02:06 ddyett

I have a strong feeling that this scenario should land in the Kiota self-serve category for Graph. So basically building your own SDK based on our OpenAPI description. This will help tremendously with size and offer the right level of trimming.

sebastienlevert avatar Apr 12 '24 13:04 sebastienlevert