在VisualStudio中创建IronPython项目时出错;“调用的目标引发了异常。”

2024-10-06 07:16:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个在C上内置GUI的解决方案,我想在解决方案中创建一个IronPython项目,它将从C代码中调用,但我甚至不能创建它。在

我使用的是CodePlex和ironpython2.7中的python工具

编辑:这是我在活动日志.xml在

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Failed to load language 'IronPython 2.7.2.1': Method not found: '!!1[] Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(!!0[], System.Func2<!!0,!!1>)'. ---> System.MissingMethodException: Method not found: '!!1[] Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(!!0[], System.Func2)'. at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary2 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) at Microsoft.IronPythonTools.Interpreter.RemoteInterpreter..ctor() at Microsoft.IronPythonTools.Interpreter.RemoteInterpreterProxy..ctor() --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark) at System.Activator.CreateInstance(String assemblyName, String typeName) at System.AppDomain.CreateInstance(String assemblyName, String typeName) at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName) at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName) at Microsoft.IronPythonTools.Interpreter.IronPythonInterpreter.CreateDomain(RemoteInterpreterProxy& remoteInterpreter) at Microsoft.IronPythonTools.Interpreter.IronPythonInterpreter.InitializeRemoteDomain() at Microsoft.IronPythonTools.Interpreter.IronPythonInterpreter..ctor(IronPythonInterpreterFactory factory, PythonTypeDatabase typeDb) at Microsoft.IronPythonTools.Interpreter.IronPythonInterpreterFactory.CreateInterpreter() at Microsoft.PythonTools.Repl.PythonReplEvaluator.get_ReplAnalyzer() at Microsoft.PythonTools.Extensions.GetAnalyzer(ITextView textView) at Microsoft.PythonTools.Intellisense.IntellisenseControllerProvider.TryCreateIntellisenseController(ITextView textView, IList1 subjectBuffers) at Microsoft.VisualStudio.Language.Intellisense.Implementation.IntellisenseManagerConnectionListener.<>c_DisplayClass5.b_1(IIntellisenseControllerProvider provider) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata,TExtensionInstance](Object errorSource, Lazy2 provider, Func2 getter)

生成的代码如下(此项目仍不显示在解决方案中)

项目1.py:

print("hello world")

由于我使用的是python2.7,所以将上面的代码改为print "Hello world",但它没有解决问题

项目1.pyproj:

^{pr2}$

Tags: stringobjectsystematmicrosoftruntimeironpythonboolean
1条回答
网友
1楼 · 发布于 2024-10-06 07:16:50

最后的解决方案是卸载所有的IronPython(2.6和2.7),然后卸载用于VisualStudio的Python工具。然后重新安装IronPython2.7,在选择组件时不安装任何“工具”(我认为这是一个重要部分,因为据我所知,它们相互冲突),然后重新安装Python工具版本1.5(我使用VS2012)

相关问题 更多 >