尝试让Flask应用程序调用某些第三方.NET代码。我正在使用我在Ubuntu 14.04主机上构建的pythonnet。尝试过开发和掌握分支机构。
该应用程序与Flask内置开发服务器完美配合,该服务器默认运行在localhost:5000上。
问题在于我将Apache / WSGI投入到混合中。如果有人想要的话,我可以继续讨论WSGI配置的细节(实际上是通过Puppet进行部署,但这是无关紧要的)但是为了简洁起见,我们说这是相当标准的。我之前已经设置了WSGI应用程序。 Web应用程序在尝试使用其中一个.NET对象时崩溃,而这些对象又尝试反序列化一些POSTed JSON。堆栈跟踪如下:
ERROR:SdoEngine:Failed to process request body: System.TypeInitializationException: The type initializer for 'System.Web.Script.Serialization.JavaScriptSerializer' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.ArgumentException: The 'ExeConfigFilename' argument cannot be null.
at System.Configuration.ExeConfigurationHost.CheckFileMap (ConfigurationUserLevel level, System.Configuration.ExeConfigurationFileMap map) <0x401bd900 + 0x00130> in <filename unknown>:0
at System.Configuration.ExeConfigurationHost.InitForConfiguration (System.String& locationSubPath, System.String& configPath, System.String& locationConfigPath, IInternalConfigRoot root, System.Object[] hostInitConfigurationParams) <0x401bd4d0 + 0x0011c> in <filename unknown>:0
at System.Configuration.InternalConfigurationSystem.InitForConfiguration (System.String& locationConfigPath, System.String& parentConfigPath, System.String& parentLocationConfigPath) <0x401bd470 + 0x0004d> in <filename unknown>:0
at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) <0x401bd2e0 + 0x0008d> in <filename unknown>:0
at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) <0x401bd060 + 0x0007c> in <filename unknown>:0
at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (ConfigurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) <0x401bc720 + 0x002b1> in <filename unknown>:0
at System.Configuration.ClientConfigurationSystem.get_Configuration () <0x401bc5b0 + 0x00049> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.get_Configuration () <0x401bc5b0 + 0x000c9> in <filename unknown>:0
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) <0x401bc530 + 0x0001f> in <filename unknown>:0
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) <0x401bc3a0 + 0x00037> in <filename unknown>:0
at System.Web.Script.Serialization.JavaScriptSerializer..ctor (System.Web.Script.Serialization.JavaScriptTypeResolver resolver, Boolean registerConverters) <0x401bbe60 + 0x0006c> in <filename unknown>:0
at System.Web.Script.Serialization.JavaScriptSerializer..cctor () <0x401bbde0 + 0x00032> in <filename unknown>:0
--- End of inner exception stack trace ---
at StormTestCoreLib.ScreenDefinition.ScreenDef.DeSerialize (System.String serializedObject) <0x401bbae0 + 0x00045> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x401b0780 + 0x000b7> in <filename unknown>:0
按照www.mono-project.com/docs/getting-started/install/linux/安装Mono版本4.2.2。还从Mono Github repo的源代码构建了它,结果相同。在版本bug上修复了一个相关的3.8,这是我确实拥有的修复程序。我知道,因为我在单声道lib上运行nm
,mono_domain_set_config
就在那里。
我是单声道新手。它看起来像配置问题。我已经比较了开发服务器和WSGI环境变量,没有什么比这更让我感到惊讶了。在这一点上,我会感激任何人可能有的任何指示。
PD:不得不删除一些链接。遗憾的是,声誉不足。我希望这个问题很清楚。答案 0 :(得分:1)
原来这是pythonnet中的一个错误。如果我在mono_domain_set_config
中添加对PyNet_Init
的调用,问题就会消失。
diff --git a/src/monoclr/pynetinit.c b/src/monoclr/pynetinit.c
index eaa1d9c..ed247f2 100644
--- a/src/monoclr/pynetinit.c
+++ b/src/monoclr/pynetinit.c
@@ -31,6 +31,7 @@ PyNet_Args* PyNet_Init(int ext) {
pn_args->shutdown_name = "Python.Runtime:Shutdown()";
pn_args->domain = mono_jit_init_version(MONO_DOMAIN, MONO_VERSION);
+ mono_domain_set_config(pn_args->domain, ".", "Python.Runtime.dll.config");