How to use IronPython with App.Config?

前端 未结 6 1832
醉梦人生
醉梦人生 2021-02-05 07:13

I have a class library that is usually called from a .net console or web application. It integrates with various components, and relies on an app.config or web.config.

I

6条回答
  •  粉色の甜心
    2021-02-05 07:43

    For a workaround what I did was fill the AppSettings collection for the ConfigurationManager static class "manually", so I created a PY Script and run an "import" of it on IronPython and the settings then will be available for the class library. However I couldn assing values to the ConnectionStrings collection :(

    my script looks like this

    import clr
    clr.AddReferenceToFileAndPath(r'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll')
    from System.Configuration import *
    ConfigurationManager.AppSettings["settingA"] = "setting A value here"
    ConfigurationManager.AppSettings["settingB"] = "setting B value here"
    

    It would be nice though to know a way to "load" a custom .config file to the ConfigurationManager class.

提交回复
热议问题