0

I'm writing C# that is running as a sandboxed plugin for a piece of 3rd party software. As a result, I cannot load config by specifying a file for ConfigurationManager.

I can however, set up a file on the 3rd party server and retrieve the contents as a string.

Ideally I would like to feed my config-as-string into the ConfigurationManager and have a normal C# config system. I've read the docs but couldn't see any to init config with a string (or buffer). Is there a reasonable and easy way to do this?

My fallback plan is to make a simple format of [key]=[value]\n and loading that into a Dictionary. I'd just like to avoid creating and maintaining a config system if possible.

Sherman
  • 827
  • 8
  • 16
  • This answer is loading from a database, but might be helpful: http://stackoverflow.com/questions/17070088/c-sharp-initialize-appsettings-from-database – Alexis Murray Aug 24 '15 at 15:46
  • Saw this question in the *Related* area in the sidebar that may help: https://stackoverflow.com/questions/9779962/using-net-configurationmanager-to-read-settings-from-a-string-instead-of-an-app?rq=1 – Joshua Shearer Aug 24 '15 at 15:47
  • You can put your config into the 3rd party software and access it via the ConfigurationManager or load your configuration file manually. This is the two options I see – Tristan Djahel Aug 24 '15 at 15:47
  • 1
    If you save your config-as-string into a temp file, you might be able to load it using these techniques: http://stackoverflow.com/questions/16425407/configurationmanager-appsettings-use-another-config-file – Fidel Aug 24 '15 at 15:54
  • @Fidel Looks like you are right. And another similar answers at [here](http://stackoverflow.com/questions/4738/using-configurationmanager-to-load-config-from-an-arbitrary-location) – Artyom Aug 24 '15 at 15:56
  • @MichaelMurray - No database libraries in the sandbox – Sherman Aug 24 '15 at 16:20
  • @Fidel - No file access of any kind, can't create a temp file (I probably _could_ break the sandbox, but that's a whole new can of worms) – Sherman Aug 24 '15 at 16:21
  • @Sherman I more meant taking a similar approach. Load an XML document into memory from a stream, update the ConfigurationManager like they did in that answer. – Alexis Murray Aug 24 '15 at 17:07

1 Answers1

0

I know you don't want to, but you can always roll your own. Which is just what we did in a similar situation. I posted some code I wrote for managing configuration that is thread-safe here:

Where to store "factory defaults" configuration settings, so they may be updated programmatically

My post is at the bottom.

Community
  • 1
  • 1
Mr. B
  • 2,845
  • 1
  • 21
  • 31