2

I am able to delete component using core service client, but when i am trying to create and save one, i get below mentioned exception.

client.Open();
BinaryContentData bcd = new BinaryContentData{
    UploadFromFile = fileInfo.Name,
    MultimediaType = new LinkToMultimediaTypeData(),
    Filename = fileInfo.Name,
    IsExternal = false};
ComponentData compData = new ComponentData();
compData.ComponentType = ComponentType.Multimedia;
compData.BinaryContent= bcd;
compData.LocationInfo = new LocationInfo() { OrganizationalItem = new LinkToOrganizationalItemData() {IdRef = folderuri}};  
compData.Title = MakeValidFileName(fileInfo.Name);
compData.Schema = new LinkToSchemaData() {  IdRef = schemauri };
compData.ApprovalStatus = new LinkToApprovalStatusData {IdRef = "tcm:0-0-0" };
compData.Id = "tcm:0-0-0";
client.Save(compData, new ReadOptions());
client.CheckIn(compData.Id, null);
client.Close();

Any focus on the same is appreciated.

Event Viewer shows following logs :

Unexpected item type: Schema.

Component: Tridion.ContentManager.CoreService Errorcode: 0 User: NT AUTHORITY\NETWORK SERVICE  StackTrace Information Details:   

    Unexpected item type: Schema.
  Component: Tridion.ContentManager.CoreService Errorcode: 0 User: NT AUTHORITY\NETWORK SERVICE  StackTrace Information Details:
   at Tridion.ContentManager.ContentManagement.RepositoryLocalObject.AssertValidContainer(IContainer container)
   at Tridion.ContentManager.ContentManagement.RepositoryLocalObject.AssertValidContainer()
   at Tridion.ContentManager.ContentManagement.RepositoryLocalObject..ctor(Session session, TcmUri parentId)
   at Tridion.ContentManager.ContentManagement.Component..ctor(Session session, TcmUri parentId)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Tridion.ContentManager.Session.GetNewObject(Type objectType, String containerUri)
   at Tridion.ContentManager.Session.GetNewObject(IdentifiableObjectData data)
   at Tridion.ContentManager.CoreService.CoreServiceBase.Save(IdentifiableObjectData deltaData, ReadOptions readBackOptions)
   at SyncInvokeSave(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at Tridion.ContentManager.CoreService.CoreServiceInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

while Code level debugging gives following exception message and stack trace :

Server stack trace:

   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:

at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)    at Tridion.ContentManager.CoreService.Client.ISessionAwareCoreService.Save(IdentifiableObjectData deltaData, ReadOptions readBackOptions)
6
  • 1
    Quite clearly it complains about a schema in the wrong place. Could you please post your entire code? Also, instead of Save and CheckIn use Update method Commented Nov 24, 2014 at 8:02
  • I am using default Multimedia schema URI, even if i try other schema, error persists.
    – user
    Commented Nov 24, 2014 at 8:34
  • Also if i try update call instead of save i get exception "Operation is not supported on a new item or on a null URI." which is but obvious i believe.
    – user
    Commented Nov 24, 2014 at 8:35
  • Sorry, for Create you need to use Create method, not update. As for the error, without code it's difficult to say, but I believe you assign SchemeData where LinkToSchema is expected Commented Nov 24, 2014 at 9:35
  • 1
    Double check that folderuri is indeed a folder and not schema Commented Nov 24, 2014 at 11:55

1 Answer 1

1

I would expect the AssertValidContainer method check that the item you are trying to create (or update) can actually be saved in the location that you are trying.

You may want to:

  1. Double check that you are definitely trying to create a Component (and not another type) in your code
  2. Ensure that you are trying to save the (Multimedia) Component in the correct location (a Folder).
  3. If you are definitely trying to save an item into a Folder, then make sure that the Folder does not have a Mandatory Linked Schema set (or that it is the correct type).

enter image description here

You may want to test this by trying to create the same type of Component in this Folder using the standard Content Management Explorer (CME) interface.

6
  • hi Jonathan, I have already linked schema to folder i am creating inside and also able to manually create multimedia component based on linked schema.
    – user
    Commented Nov 24, 2014 at 10:52
  • @user Have you tried removing the linked Schema from the Folder? Commented Nov 24, 2014 at 11:25
  • Yes tried removing same. Still same exception. Updated exception message in description
    – user
    Commented Nov 24, 2014 at 12:22
  • @user Thanks for the updated information. Are you sure that folderuri and schemauri variables are correct (and not the wrong way around)? Have you tried writing these out using a log.Info to confirm? Commented Nov 24, 2014 at 13:12
  • Yes they are correct and re verified using application level logs.
    – user
    Commented Nov 24, 2014 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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