Update to 1.7 - Media picker error

Topics: Installing Orchard, Troubleshooting
Aug 3, 2013 at 6:40 PM
After running the upgrade, I can't access the Content menu item. I get the following error.
Please advise.

Server Error in '/' Application.

Input string was not in a correct format. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.FormatException: Input string was not in a correct format.

Source Error: 



Line 6:      var field = (MediaLibraryPickerField) Model.ContentField;
Line 7:      string name = field.DisplayName;
Line 8:      var mediaParts = field.MediaParts;
Line 9:  
Line 10:     var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();
  

 Source File:  c:\DWASFiles\sites\gptur\VirtualDirectory0\site\wwwroot\Modules\Orchard.MediaLibrary\Views\Fields\MediaLibraryPicker.SummaryAdmin.cshtml    Line:  8 
Developer
Aug 3, 2013 at 7:06 PM
Do you have any more details?

MediaParts is a lazy loaded object, so I reckon the exception is actually occurring before this. Any chance you could attach a debugger and see if there is an inner exception?
Aug 3, 2013 at 7:09 PM

Hum, I don’t see how… And this is all the details I have… Suggestions for doing that?

Aug 3, 2013 at 8:16 PM
Restart on your backup is the best solution if you can't give more details, have you a backup?
Aug 3, 2013 at 8:18 PM

Ok, I know what the problem is now. I had a media picker field on a content part, and some content was pointing to external images. This, apparently, doesn’t work anymore! If I take that field it works. Suggestions?

Aug 3, 2013 at 8:46 PM
I've temporarily selected a link field type to replace and everything is working now. But I wanted a way to either insert a picture from the library or as an external link. How can I do so?
Aug 6, 2013 at 7:15 PM
i have the same error.
My sitution is following:
i have added mediapickerfield in blogpost content item.
then i decided to upgrade to 1.7
i followed all the instruction

"Disable the module Media
Enable the module Media Library
Click on Upgrade To 1.7 from the menu
Select the Media Library tab and click Migrate
In the Media Picker Field section click Migrate"

after it i have an error when i access to new "Media Library Picker Field"

what should i do to correct it?

stack trace:



"
Сведения об исключении: System.FormatException: Входная строка имела неверный формат.

Ошибка источника:


Строка 6: var field = (MediaLibraryPickerField) Model.ContentField;
Строка 7: string name = field.DisplayName;
Строка 8: var mediaParts = field.MediaParts;
Строка 9:
Строка 10: var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();
"

[FormatException: Входная строка имела неверный формат.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10689507
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145
System.Int32.Parse(String s) +23
System.Linq.WhereSelectArrayIterator2.MoveNext() +66
System.Linq.Buffer
1..ctor(IEnumerable1 source) +127
System.Linq.Enumerable.ToArray(IEnumerable
1 source) +46
Orchard.MediaLibrary.Fields.MediaLibraryPickerField.DecodeIds(String ids) +130
Orchard.MediaLibrary.Fields.MediaLibraryPickerField.get_Ids() +29
Orchard.MediaLibrary.Handlers.<>c__DisplayClass5.<Loading>b__2(IEnumerable1 x) +23
Orchard.ContentManagement.Utilities.LazyField
1.GetValue() in c:\Orchard\src\Orchard\ContentManagement\Utilities\LazyField.cs:24
Orchard.MediaLibrary.Fields.MediaLibraryPickerField.get_MediaParts() +9
ASP._Page_Modules_Orchard_MediaLibrary_Views_Fields_MediaLibraryPicker_SummaryAdmin_cshtml.Execute() in c:\Users\Smirnov\Documents\My Web Sites\MixFacts\Modules\Orchard.MediaLibrary\Views\Fields\MediaLibraryPicker.SummaryAdmin.cshtml:8
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +103
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) +277
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +91
Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.ShapeTemplateBindingStrategy.Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) in c:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:139
Orchard.DisplayManagement.Descriptors.ShapeTemplateStrategy.<>c__DisplayClass28.<Discover>b__15(DisplayContext displayContext) in c:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs:126
Orchard.DisplayManagement.Descriptors.<>c__DisplayClass5.<BoundAs>b__2(DisplayContext displayContext) in c:\Orchard\src\Orchard\DisplayManagement\Descriptors\ShapeAlterationBuilder.cs:55
Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Process(ShapeBinding shapeBinding, IShape shape, DisplayContext context) in c:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:177
Orchard.DisplayManagement.Implementation.DefaultDisplayManager.Execute(DisplayContext context) in c:\Orchard\src\Orchard\DisplayManagement\Implementation\DefaultDisplayManager.cs:81
Orchard.DisplayManagement.Implementation.DisplayHelper.ShapeExecute(Object shape) in c:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:86
Orchard.DisplayManagement.Implementation.DisplayHelper.Invoke(String name, INamedEnumerable`1 parameters) in c:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:43
Orchard.DisplayManagement.Implementation.DisplayHelper.TryInvoke(InvokeBinder binder, Object[] args, Object& result) in c:\Orchard\src\Orchard\DisplayManagement\Implementation\DisplayHelper.cs:29
CallSite.Target(Closure , CallSite , Object , Object ) +193
Orchard.Core.Shapes.CoreShapes.ContentZone(Object Display, Object Shape, TextWriter Output) in c:\Orchard\src\Orchard.Web\Core\Shapes\CoreShapes.cs:274
Aug 6, 2013 at 7:35 PM
Coordinator
Aug 7, 2013 at 12:15 AM
Did anyone open a bug for this one ? Does it seem like a valid repro is to add a Media Picker to a blog post ?
Aug 7, 2013 at 12:17 AM

I still haven’t tried this on a clean installation to see if it happens again. I believe this has to do with the old media picker allowing external pictures and this one not.

Aug 10, 2013 at 9:54 PM
This can happen because the records in the case of Media Picker were stored with your URL and now do with your ID.

See table Orchard_Framework_ContentItemVersionRecord

OLD FORMAT EXAMPLE
<Data><Thumbnails><ThumbnailSmall>~/Media/Default/images/News/2013/07/Workshop-Theater-Dance---tec-clasica-07-08-septiembre-2013_200x130.jpg</ThumbnailSmall></Thumbnails></Data>

NEW FORMAT EXAMPLE
<Data><Thumbnails><ThumbnailSmall>{345}</ThumbnailSmall></Thumbnails></Data>

{345} is the id of the record corresponding to the stored image by the new module MediaLibrary.
Aug 23, 2013 at 8:09 AM
I also encountered the same problem.
Seek a solution.
Oct 18, 2013 at 12:09 AM
I have this error right now. Is there any solution to this?
Dec 4, 2013 at 4:20 PM
I'm also getting the same problem. Looks to me that the upgrade module is not migrating mediapickerfields correctly in all cases, leaving the old url in place in the Orchard_Framework_ContentItemVersionRecord table.

I re-loaded the same database and tried to repro a second time with debugging on, and it worked fine. One difference may have been that in the first instance I enabled the new media library AND disable the old media modules before running the upgrade module. In the second time through I left the old media modules enabled until after I had run the upgrade module actions.
Dec 4, 2013 at 5:25 PM
This problem has existed for a LONG time and nobody seems to care.

I can't upgrade any sites to 1.7 because of this...
Coordinator
Dec 10, 2013 at 6:51 AM
What do you mean nobody seems to care? Sébastien answered above and asked if somebody had open a bug for this and nobody bothered to answer. Just file a bug.
Dec 11, 2013 at 1:48 PM
BertrandLeRoy wrote:
What do you mean nobody seems to care? Sébastien answered above and asked if somebody had open a bug for this and nobody bothered to answer. Just file a bug.
Frankly, I thought it was such an egregious bug and so easy to duplicate that someone on the team would just jump to fixing it as soon as the team was aware that it existed, not wait 5 months for someone to add a bug about it.
Dec 11, 2013 at 1:49 PM
Coordinator
Dec 11, 2013 at 5:32 PM
Edited Dec 11, 2013 at 5:32 PM
Thanks, it is, although it's better to include details in the bug itself if you want to maximize the chances that it's going to be processed efficiently. Votes are also a factor. You don't manage a project this size on the corner of a napkin, I hope you'll understand. We need bugs to be filed so they can be tracked and looked at. Also understand that this is an open source project and that "the team" is all of us. Typically, bugs get fixed by the people they affect.
Dec 11, 2013 at 5:53 PM
Understandable.

As far as Open Source goes, I am all for contributing, but I don't find this the simplest code base to just dive in and work with, so I figured I'd leave this one to people who were more familiar with it.

I will try to add some more details to the bug when I get a chance..
Coordinator
Dec 12, 2013 at 8:07 AM
Thanks for adding the details to the bug, that will definitely help.
Apr 6, 2014 at 8:28 PM
The issue still exists when upgrading to Orchard 1.8
Apr 21, 2014 at 11:21 PM
Has anyone started working on this?
Jan 8, 2015 at 9:34 PM
Any chance this has a fix? I'm struggling with this error now. Still experiencing this when upgrading from 1.4.2 to 1.8.1 when clicking on "Content" in the admin nav.
Line 6:      var field = (MediaLibraryPickerField) Model.ContentField;
Line 7:      string name = field.DisplayName;
Line 8:      var mediaParts = field.MediaParts;
Line 9:  
Line 10:     var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +10896279
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145
   System.Int32.Parse(String s) +23
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +127
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +46
   Orchard.MediaLibrary.Fields.MediaLibraryPickerField.DecodeIds(String ids) +130
   Orchard.MediaLibrary.Fields.MediaLibraryPickerField.get_Ids() +28
   Orchard.MediaLibrary.Handlers.<>c__DisplayClass3.<InitilizeLoader>b__1() +23
   System.Lazy`1.CreateValue() +415
   System.Lazy`1.LazyInitValue() +152
Feb 13, 2015 at 4:14 PM
The rather laborious work-around for this:

1) query the db to find what contenttypes have mediapickers on them (look in [Settings_ContentPartFieldDefinitionRecord])
2) edit those contenttypes
3) drop the field(s) that were medialibrary picker
4) re-add it with a new name (old data persists under the previous name)
5) reattach every image for that type
6) Refactor code in any alternates that uses the Media Picker Field. The object structure changed so your code will error out.