我正在尝试以编程方式发布媒体项目,但我遇到了 PublishOptions 对象的问题。在运行时,当我上传媒体项目时,正在实例化 PublishOptions 对象的代码行会中断。我收到以下消息:

"Value cannot be null. Parameter Name: item"

堆栈跟踪是:
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.Data.Managers.ItemProvider.ApplySecurity(Item item, SecurityCheck securityCheck)
at Sitecore.Data.Managers.ItemProvider.GetRootItem(Language language, Version version, Database database, SecurityCheck securityCheck)
at Sitecore.Data.Managers.ItemManager.GetRootItem(Language language, Version version, Database database)
at Sitecore.Nexus.Data.DataCommands.ResolvePathCommand.(String itemPath, Database database)
at Sitecore.Nexus.Data.DataCommands.ResolvePathCommand.(String itemPath, Database database)
at Sitecore.Nexus.Data.NexusDataApi.ResolvePath(String itemPath, Database database)
at Sitecore.Data.Engines.DataCommands.ResolvePathCommand.DoExecute()
at Sitecore.Data.Engines.EngineCommand`2.Execute()
at Sitecore.Data.Engines.DataEngine.ResolvePath(String itemPath)
at Sitecore.Data.Managers.ItemProvider.ResolvePath(String itemPath, Database database)
at Sitecore.Data.Managers.ItemProvider.GetItem(String itemPath, Language language, Version version, Database database, SecurityCheck

这是正在实例化 PublishOptions 对象的代码(它正在中断):
public void OnItemSaved(Object sender, EventArgs args)
    {
        var item = Event.ExtractParameter(args, 0) as Item;

        using (new SecurityDisabler())
        {
            if (item != null)
            {
                if (item.Paths.IsMediaItem)
                {
                    var source = new Database("master");
                    var target = new Database("web");


                    var options = new PublishOptions(source, target, PublishMode.SingleItem, item.Language, DateTime.Now)
                                      {
                                          RootItem = item,
                                          Deep = true,

                                      };

                    var publisher = new Publisher(options);

                    publisher.PublishAsync();
                }
            }
        }
    }

我收到此错误的原因可能是什么?

最佳答案

试试这个,看看这是否有效,我猜它与数据库有关。

public void OnItemSaved(Object sender, EventArgs args)
    {
        var item = Event.ExtractParameter(args, 0) as Item;

        using (new SecurityDisabler())
        {
            if (item != null)
            {
                if (item.Paths.IsMediaItem)
                {
                    var source = Factory.GetDatabase("master");
                    var target = Factory.GetDatabase("web");

                    var options = new PublishOptions(source, target,
                                                     PublishMode.SingleItem, item.Language,
                                                     DateTime.Now)
                                      {
                                          RootItem = item,
                                          Deep = true,
                                      };

                    var publisher = new Publisher(options);

                    publisher.PublishAsync();
                }
            }
        }
    }

关于c# - 尝试以编程方式发布媒体项目时,PublishOptions 失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19958800/

10-13 07:48