我正在用C#开发制图应用程序,我计划使用IronPython作为应用程序的脚本扩展。我已成功使用IronPython数月,大多数用户没有任何问题,但有一小部分用户遇到问题。
在其中一个人的帮助下,我设法挖出了异常堆栈跟踪。调用Python.CreateEngine()
方法时发生异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException:
Failed to load language 'IronPython 2.6.2': Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.Scripting.Actions.TopNamespaceTracker.PublishComTypes(Assembly interopAssembly)
at IronPython.Runtime.Binding.PythonBinder.DomainManager_AssemblyLoaded(Object sender, AssemblyLoadedEventArgs e)
at IronPython.Runtime.Binding.PythonBinder..ctor(PythonContext pythonContext, CodeContext context)
at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary`2 options)
--- End of inner exception stack trace ---
at Microsoft.Scripting.Runtime.LanguageConfiguration.LoadLanguageContext(ScriptDomainManager domainManager, Boolean& alreadyLoaded)
at Microsoft.Scripting.Runtime.DlrConfiguration.LoadLanguageContext(ScriptDomainManager manager, LanguageConfiguration config)
at Microsoft.Scripting.Runtime.DlrConfiguration.TryLoadLanguage(ScriptDomainManager manager, AssemblyQualifiedTypeName providerName, LanguageContext& language)
at Microsoft.Scripting.Runtime.ScriptDomainManager.GetLanguageByTypeName(String providerAssemblyQualifiedTypeName)
at Microsoft.Scripting.Hosting.ScriptRuntime.GetEngineByTypeName(String assemblyQualifiedTypeName)
at IronPython.Hosting.Python.GetEngine(ScriptRuntime runtime)
我在Google上找不到任何与此相关的内容。 有关用户环境的一些信息:
我自己使用Win7 64bit,但我没有遇到任何此类问题。
答案 0 :(得分:1)
异常发生在IronPython的COM互操作代码中,但我不确定为什么 - 发生异常的代码将COM类型从互操作程序集中拉出来。当异常发生时,您必须(以某种方式)弄清楚AppDomain中正在加载哪个程序集,这可能需要实时调试或自定义IronPython构建。
我不确定它是否是IronPython中的错误,或者用户机器上是否有一个松鼠COM对象导致IronPython中断,但我的猜测是后者。