Getting null reference error while trying to create the schema. Using Tridion 2013 SP1 and code written in C#

Code Snippet :

SchemaData mmSchema = (SchemaData)client.GetDefaultData(ItemType.Schema, locationId, new ReadOptions());    
var list = client.GetSystemWideList(new MultimediaTypesFilterData());
var multimediaType = list.OfType<MultimediaTypeData>().Select(mt => mt.Id);

LinkToMultimediaTypeData[] arrayLinkToMultimediaTypeData = new LinkToMultimediaTypeData[multimediaType.Count()];
var i = 0;
foreach (var item in multimediaType)
    var allowedMultimediaType = new LinkToMultimediaTypeData { IdRef = item };
    arrayLinkToMultimediaTypeData[i] = allowedMultimediaType;
    i += 1;
mmSchema.Title = title;
mmSchema.Description = title;
mmSchema.Purpose = SchemaPurpose.Multimedia;
mmSchema.AllowedMultimediaTypes = arrayLinkToMultimediaTypeData;
mmSchema = client.Create(mmSchema, new ReadOptions()) as SchemaData;

Thank you in advance for any help.

  • Can you improve your question noting the environment, versions, etc. Aug 17 '16 at 11:51
  • Can you check the number of items in multimediaType?
    – robrtc
    Aug 17 '16 at 13:54

In the foreach loop you are redefining i each time, so i will always be 0. Consequently I suspect the remaining items in your array will by default be null.

  • But atleast one last data will be there, though the others are null.So what I undersstand in this case multimedia type can not be null.Thank you. Aug 17 '16 at 12:15

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.