Implementing Document.GetService[LibraryManager]() in the script at times results in a "TypeError: cannot access protected member GetService without a Python subclass of Document."

Implementing Document.GetService[LibraryManager]() in the script at times results in a "TypeError: cannot access protected member GetService without a Python subclass of Document."

book

Article ID: KB0070786

calendar_today

Updated On:

Products

Spotfire Analyst

Description


The following line of code Document.GetService[LibraryManager]() in an IronPython script at times throws an error when used in an incorrect context. e.g when used in the script that aims to Save an analysis file to the Library.

The below error in the IronPython script often occurs when attempting to access a protected member incorrectly. 
 
IronPython.Runtime.Exceptions.TypeErrorException: cannot access protected member GetService without a python subclass of Document
at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Spotfire.Dxp.Application.IronPython27.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)


TypeError: cannot access protected member GetService without a python subclass of Document
cause of the error

Issue/Introduction

This article talks about the error originating from the following line of code Document.GetService[LibraryManager]() in an IronPython script "TypeError: cannot access protected member GetService without a Python subclass of Document."

Environment

All

Resolution

To resolve this error, change the following line of code 
 
lm = Document.GetService[LibraryManager]()

To :
 
lm = Application.GetService[LibraryManager]()

Additional Information

Doc : Spotfire API Reference  Doc : Document Class