Forum Cross Platform with Xamarin

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Windows Phone AppDomain.CurrentDomain.GetAssemblies(); Bug or Feature?

DavidStrickland0DavidStrickland0 USMember ✭✭✭
edited October 2015 in Cross Platform with Xamarin

On windows Phone AppDomain.CurrentDomain.GetAssemblies(); works different then on Android. The question is which is the bug and which is the feature.

Create a New Android Project add a new EMPTY Android Class library and reference from the first project.
Place

            assemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int assem = 0; assem < assemblies.Length; assem++)
            {
                System.Diagnostics.Debug.WriteLine(assemblies[assem].GetName().Name);
            }

Inside the Activity Oncreate. Run app.
Notice the Android Library appears in the list of assemblies. Basically what I would expect.

Repeat process for Windows Phone.

Create a Windows Phone Project add a new EMPTY Windows Class Library and reference it from the first project.

Place

            assemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int assem = 0; assem < assemblies.Length; assem++)
            {
                System.Diagnostics.Debug.WriteLine(assemblies[assem].GetName().Name);
            }

Inside The Constructor for MainPage. Run app.
Notice the Windows Phone Library does NOT appear in the list of assemblies. Now if you add a method to the Windows Phone Library and call it from somewhere in the code then the assembly will appear.

Why is this an issue? Xamarin Forms uses 3 Attributes to tie in functionality at runtime. ExportImageSourceHandler, ExportCell, ExportRenderer If the assemblies aren't there then the functionality does get tied in.

My first guess was that the Linker In its wisdom was removing the reference to the dll since we arean't using it. However the Android and Windows Code are both built by MSBuild so why is one droping the reference and one keeping it?

So the question is whose bug is it or is it?

Xamarin.Forms for daring to use AssemblyAttributes.
MsBuild Linker for removing them in one and keeping them in another.

Or does it lay in another park altogether?

Is this something we could reasonably expect to get fixed or should we just learn to live with it?

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    If no code uses an assembly directly then it is likely not being included at all, and that is not done by the linker (it's done before the linker). I'm certain this is true for Xamarin.Android and Xamarin.iOS, but I know less about the behavior for Windows Phone. Still, based on your observations it seems likely to be the problem. I think Xamarin has done some stuff to cause implicit usages of assemblies for Xamarin.Forms renderers and such, but they don't control the build system for Windows Phone so you may be on your own there.

Sign In or Register to comment.