gpt4 book ai didi

c# - 在 VisualStudio 中创建 IronPython 项目时出错; "Exception has been thrown by the target of an invocation."

转载 作者:行者123 更新时间:2023-11-28 20:50:20 25 4
gpt4 key购买 nike

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

我正在使用 CodePlex 和 IronPython 2.7 中的 python 工具

编辑:这是我在 ActivityLog.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.Func<code>2<!!0,!!1>)'. ---> System.MissingMethodException: Method not found: '!!1[] Microsoft.Scripting.Utils.ArrayUtils.ConvertAll(!!0[], System.Func</code>2)'. at IronPython.Runtime.PythonContext..ctor(ScriptDomainManager manager, IDictionary<code>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) 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, IList</code>1 subjectBuffers) at Microsoft.VisualStudio.Language.Intellisense.Implementation.IntellisenseManagerConnectionListener.<>c_<em>DisplayClass5.b</em>_1(IIntellisenseControllerProvider provider) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata,TExtensionInstance](Object errorSource, Lazy<code>2 provider, Func</code>2 getter)

生成的代码如下(该项目在Solution中仍然没有显示)

项目1.py:

print("hello world")

将上面的改成print "Hello world"因为我使用的是 Python 2.7 但它没有解决问题

project1.pyproj:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>690e6ad3-edb2-42cc-8db1-85cdf487d241</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>WebScraper.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
<InterpreterId>80659ab7-4d53-4e0c-8588-a766116cbd46</InterpreterId>
<LaunchProvider>IronPython (.NET) launcher</LaunchProvider>
<InterpreterVersion>2.7</InterpreterVersion>
<OutputPath>.</OutputPath>
<Name>WebScraper</Name>
<RootNamespace>WebScraper</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<None Include="WebScraper.py" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
</Project>

最佳答案

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

关于c# - 在 VisualStudio 中创建 IronPython 项目时出错; "Exception has been thrown by the target of an invocation.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12679632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com