16

I have a xamarin PCL that builds fine in x86 Debug mode. When I switch it to Release Mode (x86 or x64) or x64 Debug, I am getting runtime exceptions. It probably relates to

https://forums.xamarin.com/discussion/57810/issue-with-xamarin-forms-in-windows-uwp-app-compiled-in-the-release-mode

but I don't know what other assembly I'm using. How can I tell?

My computer is x64. When I run x64 in either debug or release I get

Exception "System.NotImplementedException" in MyApp.Interop.dll. Additional Info Arg_NotImplementedException.

Before entering the constructor App(). The call to the constructor is here:

LoadApplication(new MyApp.App());

When I build x86 I get a little bit further. It gets into the MyAppConstructor and calls the xaml constructor and gives exception:

System.Reflection.MissingMetadataException in System.Private.Reflection.Core.dll AdditionalInfo:Arg_InvokeMethodMissingMetadata, System.EventHandler. For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485

So it looks like a Xaml assembly I'm missing. How do I find out what assembly I need to add?

I put it back on Debug, but turned it to "use the Native Compiler" so I could get more details on the exceptions:

x86: Additional information: Cannot create a delegate on type 'System.EventHandler' as it is missing metadata for the Invoke method. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616867

x64: An exception of type 'System.NotImplementedException' occurred in Xamarin.Forms.Platform.UAP.dll but was not handled in user code

Additional information: The method or operation is not implemented.

UPDATE: I am guessing x64 is not supported in Xamarin because no mobile product has x64 processor? Still leaves the problem with the x86 release. I have tried adding the following assemblies in my Universal App.xaml.cs

  List<Assembly> assembliesToInclude = new List<Assembly>();
  assembliesToInclude.Add(typeof(MyApp.MyAppMainPage).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.ImageSource).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.StackLayout).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.Label).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.Button).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.FormattedString).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.Span).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.Image).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.ScrollView).GetTypeInfo().Assembly);
  assembliesToInclude.Add(typeof(Xamarin.Forms.WebView).GetTypeInfo().Assembly);
  // add this line
  Xamarin.Forms.Forms.Init(e,assembliesToInclude); // requires the `e` parameter

where MyAppMainPage is the xaml page I try to load in my PCL and the rest are the UI elements that the page is made up of.

I now see this Exception thrown for x86:

'System.PlatformNotSupportedException' in System.Private.Interop.dll Exception thrown: 'System.AggregateException' in System.Private.Threading.dll Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.Reflection.Core.dll

Why would the platform not be supported? Xamarin supports Universal right?

Seth Kitchen
  • 1,526
  • 19
  • 53
  • 1
    Looks like you're trying all the right things, obviously you've cleaned and deleted all files in bin folder? Is there any clues by turning up the build log verbosity and comparing debug vs release – Jeremy Thompson Dec 22 '15 at 22:26
  • @JeremyThompson How do I turn up the build log verbosity? – Seth Kitchen Dec 22 '15 at 22:37
  • 1
    In Visual Studio go to Tools->Options then find the Project and Solutions->Build and Run node. – Jeremy Thompson Dec 22 '15 at 22:40
  • @JeremyThompson That seems to give me more data when building, but not sure I'm getting anything more during runtime. I did catch one more exception which I have added – Seth Kitchen Dec 22 '15 at 22:53
  • 1
    Weird **PlatformNotSupportedException**, if it works it debug it should be supported in release – Jeremy Thompson Dec 22 '15 at 22:58

1 Answers1

9

I have added a Directives file. Add a file with .rd.xml ending. Mine was MyApp.rd.xml. Then include the types the exception says are missing. Mine was System.EventHandler. Here is my code (you probably don't need the other two).

<?xml version="1.0" encoding="utf-8"?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
  <Type Name="MyApp.MyAppMainPage" Dynamic="Required All" /> 
  <Type Name="System.EventHandler" Dynamic="Required All" /> 
  <Namespace Name="System.Private.Reflection.Core" Serialize="Required All" />
</Application>
</Directives> 

I guess in Universal Apps for Xamarin you need to include the assembly when loading embedded resources. I had to change

ImageSource.FromResource("MyApp.Images.Sign.jpg");

to

var assembly = typeof(MyAppMainPage).GetTypeInfo().Assembly;
ImageSource.FromResource("MyApp.Images.Sign.jpg",assembly);

You can check what resources you have by

foreach (var res in assembly.GetManifestResourceNames())
  System.Diagnostics.Debug.WriteLine("found resource: " + res);

x64 still broken.

Seth Kitchen
  • 1,526
  • 19
  • 53
  • I work on .NET for UWP. This is super interesting and I'd love to take a deeper look at it after the holiday. If you'd like you can mail me at dotnetnative@microsoft.com – MattWhilden Dec 23 '15 at 21:04
  • Thanks @MattWhilden I have sent you an email. Happy Holidays! – Seth Kitchen Dec 23 '15 at 21:44
  • @SethKitchen, thank you! Your method worked for me. But my app currently crashes on loading metadata for Xamarin.Forms.OnPlatform, how to solve it? I've tried adding this type to runtime directives, but it doesn't help. – pfedotovsky Feb 29 '16 at 11:09
  • @SethKitchen, any update regarding Release x64? I get the same error: Exception "System.NotImplementedException" in MyApp.Interop.dll. Additional Info Arg_NotImplementedException. – pfedotovsky Feb 29 '16 at 11:46
  • @pfedotovsky Not sure about Forms.OnPlatform, but I would try every directive you can think of. I have not read this anywhere, but I assume x64 is not implemented by Xamarin because no phones have x64 processors and Xamarin is a mobile API – Seth Kitchen Feb 29 '16 at 18:00
  • Thanks. This helped me a lot when my embedded images did not appear in the UWP Release build. – DELUXEnized May 09 '16 at 13:32
  • I saw your code: `var assembly = typeof(MyAppMainPage).GetTypeInfo().Assembly; ImageSource.FromResource("MyApp.Images.Sign.jpg",assembly);` In my XAML app i'm using the ImageResourceExtension technique, described [here](https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Embedded_Images). I tried modifying this: `var imageSource = ImageSource.FromResource(Source);` with `var assembly = typeof(CrediperDocXAML.App).GetTypeInfo().Assembly; var imageSource = ImageSource.FromResource(Source, assembly);` with no luck. What should be inside the typeof? wich class? – marco.marinangeli May 31 '16 at 14:00
  • How about the `PlatformNotSupportedException` problem? – qakmak Jun 18 '16 at 13:35
  • This thread is almost 2 years old and I've yet to find an answer to the PlatformNotSupportedException problem. UWP for Xamarin.Forms has long moved out of beta ... does anyone have any insights on how to address this? – baskren Oct 24 '17 at 12:21
  • How did you know, that it was the System.EventHandler directive? I've the same problems, but i can't see any hints by the compiler. Do i need to enable another logging? – The Chris Feb 21 '18 at 14:14