MediaParts NullReferenceException when trying to get image

Topics: Writing modules
Sep 25, 2013 at 5:42 AM
Hi all!
In my custom module in Handler class i trying to get MediaUrl of posted image (MediaLibraryPickerField) when OnPublish event is executed...
I'm trying to get MediaParts in different ways - as dynamic etc...
var co = context.ContentItem as dynamic;
var mediaPart = ((MediaLibraryPickerField)co.Article.MainImage).MediaParts.FirstOrDefault();
var url = mediaPart != null ? mediaPart.MediaUrl : default(string);
and others ways...
I can get Ids of MediaLibraryPickerField, but MediaParts always throw System.NullReferenceException

Thanks in advance and sorry for bad English....