I am trying to put together a small helper for encrypting web.config files.
Linqpad example:
var path = @"F:\project\"; var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/",new VirtualDirectoryMapping(path,true)); var config = Configuration.WebConfigurationManager.OpenMappedWebConfiguration(wcfm,"/"); var c = config.Sections["customGroup"]; c.SectionInformation.ProtectSection(null); config.Save();
This throws an exception:
Could not load file or assembly 'customGroupAssembly' or one of its dependencies. The system cannot find the file specified
Adding an assembly to LinqPad fixes errpr. I would suggest that this is because now it is a compile time reference.
Moving code into a winforms application re-introduces the problem.
I am trying to load the required assembly at runtime:
if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { byte[] assemblyBuffer = File.ReadAllBytes(this.openFileDialog1.FileName); AppDomain.CurrentDomain.Load(assemblyBuffer); MessageBox.Show("Assembly loaded!"); }
However, it still cannot find the file.
Is there a way to load a custom assembly into the runtime application domain so that the web configuration can be loaded correctly?
source share