Quantcast
Channel: Reading settings from app.config or web.config in .NET - Stack Overflow
Viewing all articles
Browse latest Browse all 29

Answer by esamaldin elzain for Reading settings from app.config or web.config in .NET

$
0
0

extra : if you are working on a Class Library project you have to embed the settings.json file.

A class library shouldn't really be directly referencing anything inapp.config - the class doesn't have an app.config, because it's not anapplication, it's a class.

  1. Go to the JSON file's properties.
  2. Change Build Action -> Embedded resource.
  3. Use the following code to read it.

var assembly = Assembly.GetExecutingAssembly();

var resourceStream = assembly.GetManifestResourceStream("Assembly.file.json");

string myString = reader.ReadToEnd();

now we have a JSON string we can Deserialize it using JsonConvert

if you didn't embed the file inside the assembly you can't use only the DLL file without the file


Viewing all articles
Browse latest Browse all 29

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>