Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Susek 6 posts 26 karma points
    Sep 14, 2009 @ 18:39
    John Susek
    0

    Umbraco 3 - Create node with Python

    I am getting a very odd error when trying to create a node in Umbraco 3.x with Python:

    Unable to cast object of type 'umbraco.cms.businesslogic.propertytype.PropertyType[]' to type 'umbraco.cms.businesslogic.propertytype.PropertyType[]'.

     

    Here is the code that I am using:

    import sys
    import clr
    clr.AddReferenceByPartialName('businesslogic')
    clr.AddReferenceByPartialName('System.DirectoryServices')
    from umbraco.BusinessLogic import *
    from umbraco.cms.businesslogic.web import *
    from umbraco.library import *

    submitted_form = RequestQueryString('submit')

    if submitted_form:
    dt = DocumentType.GetByAlias("GoalReportingFormDT")

    author = umbraco.BusinessLogic.User(0)

    doc = Document.MakeNew("Doc Name", dt, author, 7120)
    doc.Publish(author)
    doc.getProperty("agency_name").Value = agency_name
    doc.getProperty("agency_code").Value = agency_code

    PublishSingleNode(doc.Id)
    RePublishNodes(7120)

    print "<h3>Your submission has been received by the Small and Minority Business Division of AEDC.</h3>"
    else:
    print """
    <form action="(...this page...)" method="get" accept-charset="utf-8">
    (...snip...)
    </form>
    """

  • John Susek 6 posts 26 karma points
    Sep 14, 2009 @ 18:42
    John Susek
    0

    Does anyone know what might be causing this error message? Am I not creating the new document correctly? (Note: I cut out a bunch from the script for readability, e.g. initializing agency_name variable etc.)

    Should I scrap the Python idea and just use C#? Here is the full message:

     

    Exception has been thrown by the target of an invocation.
    at
    System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
    arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
    RuntimeTypeHandle typeOwner) at
    System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
    arguments, Signature sig, MethodAttributes methodAttributes,
    RuntimeTypeHandle typeOwner) at
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
    invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
    Boolean skipVisibilityChecks) at
    System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
    invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at
    System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags,
    Binder binder, Object target, Object[] providedArgs,
    ParameterModifier[] modifiers, CultureInfo culture, String[]
    namedParams) at System.Type.InvokeMember(String name, BindingFlags
    invokeAttr, Binder binder, Object target, Object[] args) at
    umbraco.scripting.python.executeFile(String file) at
    umbraco.macro.loadMacroPython(macro macro, Hashtable attributes, page
    umbPage)

    Unable
    to cast object of type
    'umbraco.cms.businesslogic.propertytype.PropertyType[]' to type
    'umbraco.cms.businesslogic.propertytype.PropertyType[]'.

    at
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey,
    Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback
    refreshAction, CacheDependency cacheDependency, TimeSpan timeout,
    GetCacheItemDelegate`1 getCacheItem) at
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey,
    Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback
    refreshAction, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
    at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String
    cacheKey, Object syncLock, CacheItemRemovedCallback refreshAction,
    TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) at
    umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey,
    Object syncLock, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
    at umbraco.cms.businesslogic.ContentType.get_PropertyTypes() at
    umbraco.cms.businesslogic.Content.createNewVersion() at
    umbraco.cms.businesslogic.Content.CreateContent(ContentType ct) at
    umbraco.cms.businesslogic.web.Document.MakeNew(String Name,
    DocumentType dct, User u, Int32 ParentId) at MakeNew##236(Object ,
    Object , Object , Object ) at
    IronPython.Runtime.Calls.FastCallable4.Call(ICallerContext context,
    Object arg0, Object arg1, Object arg2, Object arg3) at
    IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context,
    Object arg0, Object arg1, Object arg2, Object arg3) at
    IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext
    context, Object func, Object arg0, Object arg1, Object arg2, Object
    arg3) at D:\inetpub\wwwroot\arkansasedc.com
    CMS\python\goal_reporting_form.py##257(ModuleScope ) at
    IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) at
    IronPython.Hosting.CompiledCode.Execute()
  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Sep 14, 2009 @ 20:08
    Niels Hartvig
    0

    The support for IronPyhton is experimental (and outdated) and very likely to be removed in v4.1. I'd go for c#

  • John Susek 6 posts 26 karma points
    Sep 14, 2009 @ 20:53
    John Susek
    0

    Okay I will re-do this functionality using a C# usercontrol.. hopefully will be less stressful than trying to get this python stuff working. thanks..

  • John Susek 6 posts 26 karma points
    Sep 14, 2009 @ 23:00
    John Susek
    0

    Am I right in the assumption that I need a copy of Visual Studio installed so that I can compile the .dll file needed to use .net/c# for this task?

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 16, 2009 @ 05:38
    Aaron Powell
    0

    you can get the free versions of Visual Studio (http://www.microsoft.com/express/). Be sure to read the EULA to make sure you can legally use it for the kind of work you're wanting to do.

    But I *think* the .NET compilers (both C# and VB.NET) are part of the framework redistributable, or at the very least the SDK. So you don't need VS, it's just easier ;)

  • Immo Wache 69 posts 224 karma points
    Oct 05, 2009 @ 11:42
    Immo Wache
    1

    Hi John,

    I have tried some similar code (based on your sample) to create and publish a node with IronPython macro in Umbraco 4. I got the same result but a slightly better error message.

    According to this, the problem seams to be an ambigous reference to the cms assembly for the Python engine. The engine can not tell which one assembly to use, from bin folder or from assembly cache.

    So I added an explicit assembly reference to cms and now it works with code below:

    clr.AddReference('cms')
    clr.AddReference('businesslogic')
    
    from umbraco.BusinessLogic import *
    from umbraco.cms.businesslogic.web import *
    from umbraco.library import *
    
    dt = umbraco.cms.businesslogic.web.DocumentType.GetByAlias("faqQuestion")
    author = umbraco.BusinessLogic.User(0)
    
    

    # !!! 1140 is the FAQ node id on my machine, replace this with the node id of your machines parent node!!! doc = umbraco.cms.businesslogic.web.Document.MakeNew("Ultimate Question", dt, author, 1140) doc.getProperty("questionText").Value = "The Answer to the Ultimate Question of Life, the Universe and Everything?" doc.getProperty("bodyText").Value = "42" doc.Publish(author) umbraco.library.UpdateDocumentCache(doc.Id); print "<h3>A new Q&amp;A was added to the FAQ section.</h3>"

     

    HTH, Immo

  • Immo Wache 69 posts 224 karma points
    Oct 05, 2009 @ 11:57
    Immo Wache
    0

    Two small tips for writing and debugging IronPython scripts:

    1. Switch off Macro Page cache:
    Developer > Macros > [Python Macro] > Dashboard: Cache By Page > No

    2. After you modified a script for next test:
    touch web.config to let Umbraco reload the Python engine (touch means: add and delete a space to web.config and save this "modified" file)

     

  • Jonas Eriksson 930 posts 1825 karma points
    Aug 21, 2010 @ 12:41
    Jonas Eriksson
    0

    Immo, a very big thank you! for finding out and informing about this. "According to this, the problem seams to be an ambigous reference to the cms" A very useful workaround for problems with pre 4.5 IronPython.

    Btw same goes for umbraco so also add clr.AddReference('umbraco') if you are using that one.

    /Grateful

Please Sign in or register to post replies

Write your reply to:

Draft