Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono Domain Set Config #9

Merged
merged 6 commits into from
Mar 18, 2021

Conversation

C-SELLERS
Copy link
Contributor

This PR addresses issue #8

In order for Mono to carry out some managed functions it needs to have a config set for the appdomain.
Here is the info from the docs.

Description

Used to set the system configuration for an appdomain

Without using this, embedded builds will get 'System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.ArgumentException: The 'ExeConfigFilename' argument cannot be null.' for some managed calls.

Resource:
Mono Docs

I added the definition for mono_domain_set_config,
and then during initialization I give it a "dummy" if config_file is none.

Nothing else changes and the error no longer reproduces.

@C-SELLERS
Copy link
Contributor Author

Tested using the example in issue #8 in Ubuntu with Mono 5.12 and is passing 👍🏽

Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pythonnet import load
rence
AddReference("RestSharp")
from RestSharp import *
client = RestClient("https://www.google.com/")
restsharpResponse = client.Execute(RestRequest())
print(restsharpResponse.ErrorException.InnerException)>>> from clr import AddReference
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): Initialize types...
Runtime.Initialize(): Initialize types end.
Runtime.Initialize(): AssemblyManager.Initialize()...
Runtime.Initialize(): AssemblyManager.UpdatePath()...
PythonEngine.Initialize(): GetCLRModule()...
PythonEngine.Initialize(): clr GetManifestResourceStream...
>>> AddReference("RestSharp")
<System.Reflection.MonoAssembly object at 0x7f239e851438>
>>> from RestSharp import *
>>> client = RestClient("https://www.google.com/")
>>> restsharpResponse = client.Execute(RestRequest())
>>> print(restsharpResponse.ErrorException.InnerException)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'InnerException'
>>> print(restsharpResponse.Content)
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" ........

@filmor
Copy link
Member

filmor commented Mar 11, 2021

I think these are different config files. The current config_file is the global mono config from /etc/mono while the one that is neede d for mono_domain_set_config is supposed to be a local one (i.e. Your.App.dll.config). I suggest that we

  1. Rename the current config_file to global_config_file
  2. Use the config_file parameter for mono_domain_set_config

@C-SELLERS
Copy link
Contributor Author

C-SELLERS commented Mar 13, 2021

Ah I see what you mean, I was a bit confused because it was using ffi.NULL as the default, but I guess passing null to the mono_config_parse just loads in the default global config from the mono installation.

Certain features of the runtime like Dll remapping depend on a configuration file, to load the configuration file, just add:

mono_config_parse (NULL);

Which will load the Mono configuration file (typically /etc/mono/config)

I made the change and now it will use the config_file parameter for the domain configuration, and still maintain the default for mono's global config. 👍🏽

@C-SELLERS C-SELLERS changed the title Mono Set Config Mono Domain Set Config Mar 13, 2021
@filmor
Copy link
Member

filmor commented Mar 17, 2021

I adjusted the PR a bit, could you check whether this still works for you? Using an empty string has the advantage of being an invalid path name, so it can't accidentally load a dummy file that just happens to be located in the directory.

@C-SELLERS
Copy link
Contributor Author

Just tested again with your changes. Working fine! 👍🏽

Thank you @filmor !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants