question

YunusEmreELAGZ-3528 avatar image
0 Votes"
YunusEmreELAGZ-3528 asked JessieZhang-2116 edited

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

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]: /answers/storage/attachments/78539-xam1.png Actually, I can see the method in System.Net dll But Xamarin couldn't process the method properly and move the apk.

dotnet-xamarin
xam1.png (111.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
1 Vote"
JessieZhang-2116 answered JessieZhang-2116 edited

Hello,


Welcome to our Microsoft Q&A platform!

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

78659-image.png

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: https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker


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.



image.png (6.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Linking was already "None", I tried adding Android.RunTime.Preserve attribute but didn't helped.

Finally I realized "System.Net.Http.dll Couldn't resolved because of different assembly versions" and then I tried assembly version redirecting like below.

Then could find method. it works now.

Thanks.

<dependentAssembly>
<assemblyIdentity name="System.Net.Http" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.9.9.9" newVersion="4.0.0.0" />
</dependentAssembly>

0 Votes 0 ·

Congrats, and thanks for your support for xamarin.

0 Votes 0 ·