jamesmontemagno / Xamarin.Plugins

Cross-platform Native API Access from Shared Code!
MIT License
1.3k stars 380 forks source link

Media plugin: Trying to take a photo results in a XAML Parse Error exception #111

Closed boeremak closed 8 years ago

boeremak commented 8 years ago

Hi, I've added the media plugin to my PCL and also the Phone version to my Windows Phone 8.1 project. One thing that is not clear is where do I put this: Media.Plugin.MediaImplementation.OnFilesPicked(args)? In the onlaunched events? An example would be nice.

After I try to await the following code:

        public async void PhotoClick(object sender, EventArgs e)
        {
            var file = await CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions
            {

                Directory = "Test",
                Name = "test.jpg"
            });

        }

I get the following exception:

$exception  {"XAML parsing failed."}    Windows.UI.Xaml.Markup.XamlParseException
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in mscorlib.ni.dll

Stacktrace:

   at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
   at DMX.Helper.CameraCaptureUI.InitializeComponent()
   at DMX.Helper.CameraCaptureUI..ctor()
   at Media.Plugin.MediaImplementation.<TakePhotoAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at AppName.Data.Views.Page.<PhotoClick>d__2.MoveNext()

It looks like the DMX helper you use on the WinRT platform seems to be the cause, I went over the sourcecode but I am afraid I can't figure out what it might be. I've pasted the XAML from codeplex into the designer and there is nothing that intellisense picks up as being wrong.

I've updated Xamarin forms to the latest versions and I am running VS2015 Community edition.

Or does this error come from me not registering the first line?

the Photopicker does work, just the photo stuff gives an exception.

boeremak commented 8 years ago

Ok I've found the Media part, I had to add the following:

       protected override void OnActivated(IActivatedEventArgs args)
        {
            Media.Plugin.MediaImplementation.OnFilesPicked(args);
        }

To my app.xaml.cs file in my phone project. It still gives the error though.

jamesmontemagno commented 8 years ago

I haven't seen this at all, you can test out: https://www.nuget.org/packages/Xam.Plugin.Media/2.0.0-alpha2 latest version.

jamesmontemagno commented 8 years ago

Fixed in 2.0.1

wouterh commented 8 years ago

I get these XAML parse errors both with 2.0.1 and 2.1.2:

Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in mscorlib.ni.dll
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in mscorlib.ni.dll
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in mscorlib.ni.dll
Exception thrown: 'Windows.UI.Xaml.Markup.XamlParseException' in mscorlib.ni.dll

Any hints on how to solve them?

100s commented 8 years ago

Look like I am not the only one. I have the same problem with TakePhotoAsync, but PickPhotoAsync works fine.

Appears on: Windows Phone 8.1 RT Xamarin.Forms Emulator

Savier9 commented 8 years ago

Hi guys. Parsing error is showing up even within latest version (2.3.0) and applies to all Windows platforms. There is probably a typo within XAMLs in nuget version. So if you want to make it work, just download the source from Git and manually add references to Windows projects. It will work fine after then (execpt this issue: https://github.com/jamesmontemagno/Xamarin.Plugins/issues/217)

hannespreishuber commented 8 years ago

throws with 2.2 and following code the exception var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Sample", Name = "test.jpg" });

kirrek commented 8 years ago

Hello,

I am using Xam.Plugin.Media 2.3.0 but still getting XamlParseException when trying to start camera in Windows Phone project. Any solution for it? I am desperated.

Thank you very much

ozzy1873 commented 8 years ago

On Windows, make sure your Directory is set to a valid/legal directory or comment out the Directory setting to use the default.

jamesmontemagno commented 8 years ago

Fixed officially in 2.5.1-beta33! Tested and shipped!