Umbraco Document.getProperty(...).Value 抛出空引用异常

发布于 2024-09-26 12:23:02 字数 681 浏览 0 评论 0原文

我正在编写一个链接到 Umbraco 的小型应用程序(一个小型​​独立控制台应用程序,最终将作为服务器上的计划任务运行),并且我正在使用 Umbraco API (4.5.2) 来更改数据库/文档。

这是我正在做的事情的一个片段:

IEnumerable<Document> documents = Document.GetChildrenForTree(parentDocumentId);
foreach (Document doc in documents.Where(d => d.Published))
{
    doc.getProperty("myData").Value = "some data"; // Exception here
    // ...other stuff here...
}

但是,我总是得到 NullReferenceException,因为没有属性。这让我很困惑,因为我可以看到 umbraco 接口中有 5 个属性。

一位同事建议我使用 Node 而不是文档,但是我什至无法创建 Node,因为我从 Node 类构造函数中收到 NullReferenceException。

Node myNode = new Node(-1); // NullReferenceException here

有人有什么想法吗?

I am writing a small app that links into Umbraco (a small stand-alone console application that will eventually run as a scheduled task on the server) and I'm using the Umbraco APIs (4.5.2) to make changes to the database/document.

Here is a fragment of what I'm doing:

IEnumerable<Document> documents = Document.GetChildrenForTree(parentDocumentId);
foreach (Document doc in documents.Where(d => d.Published))
{
    doc.getProperty("myData").Value = "some data"; // Exception here
    // ...other stuff here...
}

However I always get a NullReferenceException because there are no properties. This confuses me because I can see that there are 5 properties in the umbraco interface.

A colleague suggested that I use a Node instead of a document, however I can't even create one as I get a NullReferenceException from the Node class constructor.

Node myNode = new Node(-1); // NullReferenceException here

Does anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事↓在人 2024-10-03 12:23:02

文档类从 umbraco 数据库获取/设置信息。由于您在带外控制台应用程序中运行代码,因此它无法找到 umbraco 上下文。因此抛出空引用异常。

您需要在 umbraco 进程内运行代码。有一个用于第三方集成的 asmx Web 服务。 /umbraco/webservices/api/documentservice.asmx

The document class gets/sets information from the umbraco database. Since your running code in an out of band console application it can't find the umbraco context. Therefore throwing a null reference exception.

You need to run the code inside of the umbraco process. There is a asmx webservice that exists for third party integration. /umbraco/webservices/api/documentservice.asmx

撩起发的微风 2024-10-03 12:23:02

实现此目的的另一种方法是使用 linq2umbraco。
有关更多详细信息,请参阅 http://our.umbraco.org/forum/core/41-feedback/7699-UmbracoLinq-in-console-app--Having-some-troubles

Another way of achieving this could be to use linq2umbraco.
for further details see http://our.umbraco.org/forum/core/41-feedback/7699-UmbracoLinq-in-console-app--Having-some-troubles

一城柳絮吹成雪 2024-10-03 12:23:02

我最近查看了 4.5.2 源代码,发现填充 Document 和 Node 对象只需要使用 umbracoDbDsn 进行连接。因此,如果您有一个名为 umbracoDbDsn 的 AppSetting,它指向一个有效的 Umbraco 数据库实例,那么您就可以了。

HTH,

本杰明

I checked out the 4.5.2 source recently, to find that populating Document and Node objects only requires a connection using umbracoDbDsn. So if you have an AppSetting called umbracoDbDsn which points to a valid Umbraco database instance, you'll be good.

HTH,

Benjamin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文