The .apk produced by release mode could not find "CloseConnectionGroups" Method Under System.Net dll.

Yunus Emre ELAGÖZ 1 Reputation point

Hi, There is a xamarin project I participated in these days. I can build the project debug mode and apk runnig properly. everthin is ok in APK. But When I want to distrubute the apk with release mode then The Project builded succeeded but APK doesn't work and throwig an error which "Method not found: void CloseConnectionGroups(string) at System.Net.Http.HttpMessagehandler.Dispose () [0x00000] in <>"![78539-xam1.png][1] [1]: /api/attachments/78539-xam1.png?platform=QnA Actually, I can see the method in System.Net dll But Xamarin couldn't process the method properly and move the apk.

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    You can try to set the linker option to None and try again , just as follows:


    For more details , you can check Linking on Android.

    The linker employs static analysis of the project's code to determine which types, methods, fields, or properties are in use and then strips any unused types, methods, fields, or properties from the final assembly, reducing the size by not having any unused code in the final assembly. On the assembly level, if no code from an assembly is used, the entire assembly will be omitted regardless of the Linker setting. It is worth noting that static code analysis will not pick up types used via reflection. This is not generally an issue with framework SDKs as they are optimized to check for this, but if you link user assemblies and use reflection to access types, etc, from the user assemblies, then you may need to explicitly preserve those types, etc, in the user assembly.

    For example:

    • You might have code that you call dynamically via System.Reflection.MemberInfo.Invoke.
    • If you instantiate types dynamically, you may want to preserve the default constructor of your types.
    • If you use XML serialization, you may want to preserve the properties of your types.

    In these cases, you can use the Android.Runtime.Preserve attribute.
    For more details,check:

    Best Regards,

    Jessie Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.