Alexander said:
How can I write to a ManifestResourceStream? Is this impossible?
This is not possible.
The manifest resource stream is a part of your EXE (or DLL.) EXEs and DLLs
are not modifiable at runtime. There are many reasons for this. One is that
the OS demand-loads binaries, i.e. it only fetches data from the EXE or DLL
as it needs it, rather than necessarily loading everything into memory at
once. If the file can change on disk at runtime, that defeats this
mechanism.
Another reason is that if you give a component a strong name, a signature is
generated at compile time. If you change the contents of the file, the
signature will no longer be valid. To be able to regenerate a valid
signature, you need to have the private key corresponding to the string
name. Distributing the private key with the application would defeat the
whole purpose of code signing because then anyone would be able to generate
a valid-looking signature.
Another reason is that normal users won't have write-access permission to
your EXE. Programs are usually installed in the Program Files directory,
and normal users are not granted write access to that directory. Only
Administrators and Power Users have that privilege, and with good reason -
it means that normal users can't mess up installed programs.
(Sadly, today most users run as administrators. But Microsoft is trying
hard to change that particular culture. And it's good that they are - an
awful lot of viruses in the wild today don't actually work if the logged in
user is not an administrator. Writing to a file in the program directory is
going to become an increasingly less useful practice.)
Another reason is that many viruses work by modifying program files. Virus
scanners sometimes detect and block attempts to modify program files because
of this.
So all in all, you really don't want to do this.
The usual way of solving the problem you state is to embed the default
settings as a resource in your assembly, but if the user changes the
settings, write the modified version out into their profile directory.