2

enter image description here

(80040000) Parameter is not valid. Unable to save Component (tcm:0-0-0).

System.Drawing.Image.FromStream(Stream,Boolean,Boolean) System.Drawing.Image.FromStream(Stream) Tridion.EventSystem.InternetEventSystemNemespace.ABCEventSystem.OnComponentSavePre(Component,SaveEventArgs,EventPhases) System.RuntimeMethodHandle.InvokeMethod(Object,Object[],Signature,Boolean) System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object,Object[],Object[]) System.Delegate.DynamicInvokeImpl(Object[]) Tridion.ContentManager.Extensibility.EventSubscription.DeliverEvent(IEnumerable1,TcmEventArgs,EventPhases) Tridion.ContentManager.Extensibility.EventSystem.DeliverEvent(IEnumerable1,TcmEventArgs,EventDeliveryPhase) Tridion.ContentManager.Extensibility.EventSystem.DeliverEvent(IdentifiableObject,TcmEventArgs,EventDeliveryPhase) Tridion.ContentManager.IdentifiableObject.Save(SaveEventArgs) Tridion.ContentManager.ContentManagement.VersionedItem.Save(Boolean) Tridion.ContentManager.ContentManagement.VersionedItem.Save() Tridion.ContentManager.BLFacade.ContentManagement.VersionedItemFacade.CreateAndCheckIn(UserContext,String,Boolean) XMLState.Save Component.Save

I would like to use SVG images on my website. However uploading this type into the multimedia schema "multimedia_picture" fails. I get the error "Parameter is not valid".

I have added 'SVG Type' to my multimedia schema. Is there anything else I am missing?

Update: Event System code added

  // only for multimedia components

if (comp.ComponentType.ToString().Equals("Multimedia")) { string mimeType = comp.BinaryContent.MultimediaType.MimeType; string filename = comp.BinaryContent.Filename;

            //only for imagaes: gif, jpeg and png
            if (mimeType.Contains("image") && !String.IsNullOrEmpty(filename))
            {
                messageLog.WriteEntry("OnComponentSavePre - resizing image - for component: " + comp.Title);

                // need to save first new component to be able to get type in next step
                if (args.IsNewItem)
                {
                    comp.Save();
                }

                BinaryContent bc = comp.BinaryContent;

                MemoryStream stream = new MemoryStream(bc.GetByteArray());

                Image image = Image.FromStream(stream);

                //reades multimedia fields
                ItemFields itemFields = new ItemFields(comp.Metadata, comp.MetadataSchema);

                if (itemFields.Contains("MM_Width"))
                {
                    NumberField width = itemFields["MM_Width"] as NumberField;
                    if (width != null && width.Value <= 0)
                    {
                      .....Code to set width.....
                    }
                }

                if (itemFields.Contains("MM_Height"))
                {
                     .....Code to set height.....
                }
                stream.Close();
                comp.Metadata = itemFields.ToXml();
                messageLog.WriteEntry("metadata updated", EventLogEntryType.Information, 0, 0);
            }
        }
  • Are you performing any processing in event system and looking at the error, it seems there is some problem with the event system. – Hiren Kaku Jul 6 '15 at 14:20
  • Yes, the event system is used to fill in the meta data fields for height and width of the svg image file, in case they are empty. – user1576 Jul 6 '15 at 14:23
  • 1
    It helps if you press the "Show Details" button on the error dialog and/or obtain the full error details from the Tridion event log. – Rick Pannekoek Jul 6 '15 at 17:42
  • @Rick thanks I have updated the "Show Details" content. – user1576 Jul 7 '15 at 5:24
  • Please notice Tridion runs your extensions in a Windows Service (and potentially in IIS). So using the System.Drawing namespace is not supported. Normally it works... but if it fails (I have only heard of one case - but there it happened unexpectedly after running for years) then there is no help to get from Microsoft. See MSDN for details. – Lars Møllebjerg Jul 8 '15 at 13:22
2

The file type (SVG) is not included in the list of supported GDI+ encoders/decoders. Hence, you are getting this error since this is an unsupported file type for Image.FromStream(). The data has to be in a supported format for the encoders/decoders for it to be used by Image class. Here is the list of supported file types: MSDN Link

If you try using a supported file format like JPG, your code will work.

Alternatively, if you want to use SVG, try converting to bitmap object first. The bitmap class has similar properties as image class that you may want to use in your code. The below code should work (though I haven't tested the same).

        BinaryContent bc = comp.BinaryContent;
        var objConvertor = TypeDescriptor.GetConverter(typeof(System.Drawing.Bitmap));
        var bmpObj = (Bitmap) objConvertor.ConvertFrom(bc.GetByteArray());
        if (bmpObj!=null)
        {
            var imageHeight = bmpObj.Height; 
            var imageWidth = bmpObj.Width;
            //any other code here
        }

You can post a different question if you still face issues on usage of SVG on stackoverflow

| improve this answer | |
  • I am still getting the same error. Posted the question here – user1576 Jul 15 '15 at 7:24
  • which line are you getting the error now? Can you please add stacktrace? – Vipin Kothari Jul 16 '15 at 5:52
0

If you have implemented event system for handling some processing for SVG images then please debug that, as it seems that issue is related to the event system.

To debug the event system:

  1. Add log statement to see what is missing.
  2. Setup remote debugging on CM server to debug the event system and step through the execution to see the processing and issues. For which process to attach, please refer: SDL Live documentation
| improve this answer | |
0

So, as can be seen in the stack trace, the problem occurs in an event handler which is feeding the binary content to the System.Drawing.Image.FromStream method, which apparently can't handle SVG.

| improve this answer | |
  • 1
    hi Rick, that is exactly what I said in my answer, that SVG is unsupported format for "image.fromstream". It is a duplicate answer – Vipin Kothari Jul 7 '15 at 19:45
  • True, I noticed your answer too late. I wanted to point out that the stack trace (which was originally not included) shows exactly what and where the problem is. – Rick Pannekoek Jul 7 '15 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.