Has anybody managed to successfully run a (non-trivial) Flask app under Apache mod_wsgi using pythonnet ? My app keeps throwing this exception:
"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"
as soon as it tries to use a clr object that deserializes some JSON. Full details here:
On this bug Mono added the mono_domain_set_config API to help with this situation. I don't see that method being called in the Mono code. Neither it seems to be called if I run the code in this other bug through gdb. However the code does not crash, as on the other hand I would expect as my version of Mono does have that bugfix. Still don't quite understand how that bug fix works though if it's not being called. Obviously missing something fairly fundamental here.
Maybe pythonnet PyNet_Init needs to explicitly call mono_domain_set_config ?
See #181. Travis build failing because it's using an ancient Mono 3.2.8 which does not even have the mono_domain_set_config fix (that was rolled out in 3.8.0). I'm on 4.2.2.
@denfromufa saw that thanks. Did try a couple of things on my fork by specifying mono versions but it doesn't work because Travis is using ancient Precise VMs. I did try the new Trusty image but the build hung out and failed. It's kind of irrelevant though as I know my fix works on both distros in fact as I have both a Precise box and a Trusty AWS instance both with Mono 4.2.2. So I'll leave it at that for the time being.
@danic maybe it is possible to download latest mono binaries (4.2.2) instead of compiling on build machine? it probably time outs before it builds due to constrained resources.
Activity
danic commented on Mar 9, 2016
It does indeed seem that adding a call to mono_domain_set_config in PyNet_Init fixes the issue:
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");Fix for pythonnet#180
danic commented on Mar 9, 2016
See #181. Travis build failing because it's using an ancient Mono 3.2.8 which does not even have the mono_domain_set_config fix (that was rolled out in 3.8.0). I'm on 4.2.2.
den-run-ai commented on Mar 9, 2016
@danic see this doc how to update mono on travis ci:
https://docs.travis-ci.com/user/languages/csharp/
danic commented on Mar 10, 2016
@denfromufa saw that thanks. Did try a couple of things on my fork by specifying mono versions but it doesn't work because Travis is using ancient Precise VMs. I did try the new Trusty image but the build hung out and failed. It's kind of irrelevant though as I know my fix works on both distros in fact as I have both a Precise box and a Trusty AWS instance both with Mono 4.2.2. So I'll leave it at that for the time being.
den-run-ai commented on Mar 11, 2016
@danic maybe it is possible to download latest mono binaries (4.2.2) instead of compiling on build machine? it probably time outs before it builds due to constrained resources.
danic commented on Mar 11, 2016
After a few disagreements with Travis I finally managed to persuade it to build it. It works now.
Fix for pythonnet#180
Fix for pythonnet#180
Merge pull request #181 from danic/master
Revert "Fix for #180"
Merge pull request #188 from pythonnet/revert-181-master
tonyroberts commented on Mar 15, 2016
I've re-opened this as the PR was against the wrong branch. Please submit a new PR against the develop branch.
Fix for pythonnet#180
Fix for pythonnet#180
Fix for pythonnet#180
tonyroberts commented on Mar 15, 2016
Done - see PR #189
Merge pull request #189 from tonyroberts/develop