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> """
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()
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 ;)
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&A was added to the FAQ section.</h3>"
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)
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.
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:
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:
The support for IronPyhton is experimental (and outdated) and very likely to be removed in v4.1. I'd go for c#
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..
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?
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 ;)
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:
HTH, Immo
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)
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
is working on a reply...