Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

.NET C# ConfigurationManager for XML configuration (app.config)

Discussion in 'Scripting' started by MirelesJ, Jul 4, 2017.

  1. MirelesJ

    MirelesJ

    Joined:
    Jun 2, 2017
    Posts:
    5
    I have scoured the Interwebs for a solution on this. Has anyone successfully implemented https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager(v=vs.110).aspx?

    I am able to build a script component based on this MSDN documentation (see above) that compiles, including adding a local copy reference of System.Configuration.dll in the local plugins folder so the code compiles at design time. I am unable to get the script to read the current value of a setting, regardless of where I place the file or how I name it. I've tried placing it where I believe the exe is built, renaming it to match the exe, all without success.

    I substitute "NameValueCollection appSettings = ConfigurationManager.AppSettings;" instead of "var appSettings = ConfigurationManager.AppSettings;", with no success.

    Regardless of what I've tried so far appSettings.Count always comes back 0, and when I try to use the AddUpdateAppSettings() procedure in the sample to create the file, it fails, too.

    I've attached my class and the app.config file (as app.config.txt, to get past the block)

    (I was unable to make this tutorial work either:
    )

    I appreciate any insights. Thank you!
     

    Attached Files:

    crns13 likes this.
  2. MirelesJ

    MirelesJ

    Joined:
    Jun 2, 2017
    Posts:
    5
    I was finally able to make the Xenfinity demo work. I think I had a stray "MonoBehavior" in one of the scripts.

    However, I am still keen to make System.Configuration work or at least learn what I am missing. Thanks!
     
    bindon likes this.
  3. IvanRibakov

    IvanRibakov

    Joined:
    Jan 23, 2018
    Posts:
    4
    Facing the same problem here - need to integrate C# library that relies on ConfigurationManager class into Unity project but not sure how to pass configuration to the library.

    Has anyone been able to successfully use ConfigurationManager with Unity project?
     
  4. YongyiLi

    YongyiLi

    Joined:
    Jan 17, 2018
    Posts:
    2
    Same problem here, and Google gives no solution. It seems I am on my own now.
     
  5. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    Working on this as well since Log4Net uses this library. Has any one found a solution by any chance?
     
    bindon likes this.
  6. reno77

    reno77

    Joined:
    Jun 10, 2019
    Posts:
    1
  7. eddbx

    eddbx

    Unity Technologies

    Joined:
    Jul 13, 2021
    Posts:
    1
    I did it on Windows. Not in editor but in built runtime. After build the project, put your config file as "YOU_PROJ.EXE.config" together with the exe.
     
    bindon likes this.