アプリケーションが起動するたびにすべてのタイプのすべてのプラグイン アセンブリを検索することを避けるために、タイプ キャッシュ システムが配置されていますが、.NET 1.1 から 2.0+ に移行すると、イベント ログに致命的な実行エンジン エラー (6B3979C6) が記録されます ( 80131506) AppDomain.Load() で
1. AppDomain が AppDomain.CurrentDomain でない場合に限ります。2. アセンブリが実行可能ファイルのディレクトリにありません。
ユーザーがプロジェクト固有のディレクトリに独自のアセンブリを提供できるようにするため、2. を回避することはできません。
1. が必要なので、型をスキミングした後に AppDomain をアンロードできます。
私はこのコードの所有者ではありませんが、十分な情報を提供していない場合は、適切な質問をすることができます。
このコードにより、キャッチできないエラーが発生します。
private static void AddAssembly( System.AppDomain appDom, Manifest manifest, string filenameWithoutExtension )
{
try
{
// Test that the assembly can be loaded...
System.Reflection.Assembly.ReflectionOnlyLoad(filenameWithoutExtension);
System.Reflection.Assembly assem = appDom.Load( filenameWithoutExtension );
ArrayList attributes = new ArrayList();
// System.Reflection.Assembly assem = System.Reflection.Assembly.LoadFrom(path+"\\"+file.Name);
object[] attribs = assem.GetCustomAttributes( typeof(PlugInAttribute), false );
if ( attribs.Length > 0 )
{
attribs = assem.GetCustomAttributes( false );
foreach ( Attribute attr in attribs )
{
object[] attrAttrs = attr.GetType().GetCustomAttributes(typeof(PlugInAttribute), false );
if ( attrAttrs.Length > 0 )
{
attributes.Add(attr.GetType().ToString());
break;
}
}
}
if ( attribs.Length > 0 || attributes.Count > 0 )
{
Assembly assy = new Assembly( manifest );
manifest.Assemblies.Add(assy);
assy.Name = filenameWithoutExtension;
assy.Version = AssemblyName.GetAssemblyName( System.IO.Path.Combine( manifest.Path, filenameWithoutExtension + ".dll") ).Version.ToString();
assy.Attributes = (ArrayList)attributes.Clone();
System.Type[] types = assem.GetTypes();
foreach (System.Type type in types )
if ( !type.IsNestedPrivate && !type.IsNestedPublic
&& !type.IsNestedAssembly )
assy.AddType( type );
}
}
catch ( Exception ex )
{
System.Diagnostics.Trace.WriteLine( "Manifest.AddAssembly Exception: " + ex.Message );
Manager.WriteException(ex);
}
}