web.config ファイルを暗号化するための小さなヘルパー ツールをまとめようとしています。
リンクパッドの例:
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();
これは例外をスローします:
Could not load file or assembly 'customGroupAssembly' or one of its dependencies.
The system cannot find the file specified
アセンブリを LinqPad に追加すると、errpr が修正されます。これは、コンパイル時の参照になったためだと思います。
コードを winforms アプリケーションに移動すると、問題が再発します。
これを使用して、実行時に必要なアセンブリをロードしようとしています:
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
byte[] assemblyBuffer = File.ReadAllBytes(this.openFileDialog1.FileName);
AppDomain.CurrentDomain.Load(assemblyBuffer);
MessageBox.Show("Assembly loaded!");
}
ただし、まだファイルが見つからないようです。
Web 構成を適切にロードできるように、カスタム アセンブリをランタイム アプリ ドメインにロードする方法はありますか?