This project is read-only.

FlickrMetaDataSynchr crash

Aug 26, 2011 at 9:30 AM

Having the same problem as missm. I've synched a number of sets without issues, but on one picture it crashes. There doesn't seem to be anything special about the picture. The log says that "too much metadata changed", but the picture only has a couple of tags. It needs updating of geolocation, tags, author - but nothing special. It only has 3 tags. All the metadata is on Flickr, and I'm trying to get it into the local pictures.

FlickrMetadataSynchr.exe Information: 0 : Updated geolocation for  picture with id \\server.lan\public\Photos\2011\2011-04-30 Trip\DSCN0270.JPG from ( , ) to (79.507767 , 25.822756).
    DateTime=2011-08-25T20:39:08.2467850Z
FlickrMetadataSynchr.exe Error: 0 : Unhandled exception occurred. The application will shut down. Exception details follow:
    DateTime=2011-08-25T20:39:13.3217850Z
FlickrMetadataSynchr.exe Error: 0 : System.IO.FileFormatException: Commit unsuccessful because too much metadata changed. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x88982F52
   --- End of inner exception stack trace ---
   at System.Windows.Media.Imaging.BitmapEncoder.SaveFrame(SafeMILHandle frameEncodeHandle, SafeMILHandle encoderOptions, BitmapFrame frame)
   at System.Windows.Media.Imaging.BitmapEncoder.Save(Stream stream)
   at Yorrick.FlickrMetadataSynchr.Local.LocalPicturesHelper.WriteCopyOfPictureUsingWic(Stream originalFile, LocalPictureMetadata metadata, String outputFileName) in C:\Sources\FlickrMetadataSynchr\Main\FlickrMetadataSynchr\Local\LocalPicturesHelper.cs:line 956
   at Yorrick.FlickrMetadataSynchr.Local.LocalPicturesHelper.UpdatePictureMetadataUsingWicWithCopy(LocalPictureMetadata metadata) in C:\Sources\FlickrMetadataSynchr\Main\FlickrMetadataSynchr\Local\LocalPicturesHelper.cs:line 846
   at Yorrick.FlickrMetadataSynchr.Local.LocalPicturesHelper.UpdatePictureMetadataUsingWic(LocalPictureMetadata metadata) in C:\Sources\FlickrMetadataSynchr\Main\FlickrMetadataSynchr\Local\LocalPicturesHelper.cs:line 754
   at Yorrick.FlickrMetadataSynchr.Local.LocalPicturesHelper.b__0(Object o) in C:\Sources\FlickrMetadataSynchr\Main\FlickrMetadataSynchr\Local\LocalPicturesHelper.cs:line 732
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at Yorrick.FlickrMetadataSynchr.Local.LocalPicturesHelper.RunWicStaThread(Object arg) in C:\Sources\FlickrMetadataSynchr\Main\FlickrMetadataSynchr\Local\LocalPicturesHelper.cs:line 1040
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)
    DateTime=2011-08-25T20:39:13.3317850Z

Aug 26, 2011 at 9:31 AM

BTW, I updated the geo information, servername and geolocation a bit - so not to give out too much personal info :).

Aug 26, 2011 at 2:20 PM

Thanks for reporting the issue including a trace of the exception. To better help me solve the problem, could you e-mail me the troublesome picture? You can send me a private message via CodePlex so you and I don't have to post our e-mailaddresses here ;)

Aug 26, 2011 at 4:14 PM

Thanks for providing me a copy of the picture that will not sync. I can reproduce your issue with that picture, and with that I've been able to implement a workaround.

The sync process will now skip the picture after this particular type of error occurs and will not crash anymore. Unfortunately I have no clue as to the underlying cause in the metadata of this picture that triggers the error, so I cannot successfully sync the metadata if this error occurs.

You can download a preview of the fixed version from SkyDrive: https://skydrive.live.com/#!/?cid=288ade681ec6e002&sc=documents&id=288ADE681EC6E002%212445. Please give it a try.

Aug 26, 2011 at 5:49 PM

Yup, that works. I still see the occasional error, but at least the programme continues now.

Thanks for the quick response!

Aug 26, 2011 at 6:01 PM

BTW, could this be the problem: http://blogs.msdn.com/b/rwlodarc/archive/2007/07/18/using-wpf-s-inplacebitmapmetadatawriter.asp.
Originally from this discussion: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8f297b11-99ba-459c-b085-1ff3ae526487.

(disclaimer: I'm not a .NET programmer - so don't blame me for stupid suggestions).

Aug 26, 2011 at 6:09 PM

My app already uses the InPlaceBitmapMetadataWriter first to try to update the metadata in the original file. That often fails. It then falls back to creating a copy of the picture with new metadata. That most often works.

The code in the app is derived from the sample in the blog post you mentioned, so it’s certainly not a stupid suggestion ;)

In the case of your picture the problem happens in the second step. I was already doing some additional investigation and I think I am on to something. I'll keep you posted.

 

Aug 26, 2011 at 6:48 PM

My guess would be that the problem is in this code: 

private const uint _MetadataPaddingInBytes = 2048;
bitmapMetadata.SetQuery("/app1/ifd/PaddingSchema:Padding", _MetadataPaddingInBytes);
bitmapMetadata.SetQuery("/app1/ifd/exif/PaddingSchema:Padding", _MetadataPaddingInBytes);
bitmapMetadata.SetQuery("/xmp/PaddingSchema:Padding", _MetadataPaddingInBytes);

I know that this comes straight from the example. The problem with this code is that your adding a hardcoded 2048 bytes as padding. If the metadata that you're trying to add to the picture is more than the 2048 bytes, it will fail. In my case, I put all the tags on Flickr, so I don't have them locally. So, it's trying to add all the tags to the local image. This could potentially fail if it's more than 2048 bytes. It could easily be more than 2048 bytes, with the author info, flickr id, tags and geo info.

 

Aug 26, 2011 at 7:01 PM

Close but not quite the problem. The problem is indeed with the padding. Padding is extra bytes that are added on top of the real metadata. This facilitates future in place updates (which are more efficient) by having extra legroom.

Somehow in your case adding padding to the metadata gives problems. Even when there are no tags to add. In my test of your picture I only added a short title and description on Flickr and no tags at all and I still get the same error as you encountered.

I have been able to change metadata in your file if I don't add padding. So my new approach is to first try padding (for the usual case that mostly works) and if that fails retry without adding padding. I am currently coding this new approach and will send you an updated version when finished for you to try.

Aug 26, 2011 at 7:43 PM

Created a second preview version with the additional change. On my computer this version successfully synced your picture. Please give it a try: https://skydrive.live.com/#!/?cid=288ade681ec6e002&sc=documents&uc=1&id=288ADE681EC6E002%212445

Aug 26, 2011 at 8:11 PM

Yup, that worked like a charm. It synced all the pictures that it skipped last time.