Troubleshooting ImageFile upload Failed in Media

Vote:
 

Hey Guys,

i have a problem. I could upload images just fine in media... 

But recently i get the error when trying to upload an image.. It says Failed. When i'm hovering it says: "Unable to cast object of type 'Castle.Proxies.ImageFileProxy' to type 'EPiServer.Core.PageData'" What the hell??!? Where did that come from?

i have a class like so:

[ContentType(GUID = "0A89E464-56D4-449F-AEA8-2BF774AB8730")]
    [MediaDescriptor(ExtensionString = "jpg,jpeg,jpe,ico,gif,bmp,png")]
    public class ImageFile : ImageData 
    {
        [Editable(true)]
        [Display(
            Name = "Description",
            Description = "Description field's description",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual String Description { get; set; }

        public virtual string Copyright { get; set; }
    }

This was working fine. We didnt update anything.. what am i missing ?

#176164
Mar 11, 2017 9:47
Vote:
 

Even saving blocks i get that weird unable to cast errors... what is happening...

anyone had this before:

#176165
Edited, Mar 11, 2017 11:51
Vote:
 

Do you have any listeners for events like contentsave of contentpublish?

The error points to some code you have that trying to do stuff when users are publishing or saving your content

#176173
Mar 13, 2017 8:24
Vote:
 

Yes i have one... 

[InitializableModule]
    [ModuleDependency(typeof(InitializableModule))]
    public class PublishEventInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            //Debugger.Break();
            context.InitComplete += Context_InitComplete;           
        }

        private void Context_InitComplete(object sender, EventArgs e)
        {
            var events = ServiceLocator.Current.GetInstance<IContentEvents>();
            events.PublishedContent += Events_PublishedContent;
        }

        private void Events_PublishedContent(object sender, ContentEventArgs e)
        {            
            /// Push notification if it's a new Coupe being published           
            if (((PageData)e.Content).PageTypeName == "CoupePage")
            {
                PageData page = (PageData)e.Content;
                //first check if the pageId exists in the custom table, if not then sent notifications to the hub
                if(!NotificationHubHelper.Exists(page.ContentLink.ID))
                {
                    AzureNotificationsHubClient client = new AzureNotificationsHubClient();
                    bool androidSent = client.SendNewArticleAndroidNotificationsAsync(page.Name, page.ContentLink.ID);
                    bool iOSSent = client.SendNewArticleiOSNotificationsAsync(page.Name, page.ContentLink.ID);
                    
                    //after add the current pageId to the custom table
                    NotificationHubHelper.UpdateOrAdd(page.ContentLink.ID);
                }               
            }           
        }

        public void Preload(string[] parameters)
        {
        }

        public void Uninitialize(InitializationEngine context)
        {
            var events = ServiceLocator.Current.GetInstance<IContentEvents>();            
            context.InitComplete -= Context_InitComplete;
            events.PublishedContent -= Events_PublishedContent;
        }
    }

How can we improve this? The publish event should only fire if the page is of type "CoupePage"

#176174
Mar 13, 2017 8:27
Vote:
 

Yes, there are the error.

To improve and make it work you need to wrap it with a test if it is the correct contentType

You can do it in many ways, but this is one:

private void Events_PublishedContent(object sender, ContentEventArgs e)
        {      
	    var coupePage = e.Content as CoupePage;

            if coupePage == null)
            {
                return;
            }
      
            
                PageData page = (PageData)e.Content;
                //first check if the pageId exists in the custom table, if not then sent notifications to the hub
                if(!NotificationHubHelper.Exists(page.ContentLink.ID))
                {
                    AzureNotificationsHubClient client = new AzureNotificationsHubClient();
                    bool androidSent = client.SendNewArticleAndroidNotificationsAsync(page.Name, page.ContentLink.ID);
                    bool iOSSent = client.SendNewArticleiOSNotificationsAsync(page.Name, page.ContentLink.ID);
                    
                    //after add the current pageId to the custom table
                    NotificationHubHelper.UpdateOrAdd(page.ContentLink.ID);
                }               
                
        }

[Pasting files is not allowed]

#176176
Edited, Mar 13, 2017 8:39
Vote:
 

thanks for the help Henrik! that works

#176186
Mar 13, 2017 11:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.