如果我利用反射的方式加载WebBrowser控件或者利用反射的方式加载包含有AxWebBrowser实例的类的时候, 就会出现以下异常:
[
System.IO.FileNotFoundException]
未能加载文件或程序集“AxInterop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。":"AxInterop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
Fusion Log:
=== 预绑定状态信息 ===
日志: 用户 = F9-JR305\Administrator
日志: DisplayName = AxInterop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
日志: Appbase = file:///R:/CTR6004/SystemManager/Compiled/
日志: 初始 PrivatePath = NULL
调用程序集: (Unknown)。
===
日志: 此绑定从 default 加载上下文开始。
日志: 未找到应用程序配置文件。
日志: 使用 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config 的计算机配置文件。
日志: 此时没有为引用应用策略(私有、自定义、分部或基于位置的程序集绑定)。
日志: 相同的绑定已出现过,因 hr = 0x80070002 而失败。
----------------------
以下是调用部分代码
----------------------
被调用的函数:
/// <summary>
/// 根据给定的类型在指定程序集中搜索所有该类型的子类, 并创建实例.
/// <summary>
/// <typeparam name="T">给定的类型</typeparam>
/// <param name="AssemblyPath">程序集物理路径</param>
/// <returns>实例</returns>
public static T[] GetImplementations<T>(String assemblyPath)
{
Type typeOfParam = typeof(T);
if (typeOfParam.IsEnum)
return new T[0];
Boolean isInterface = typeOfParam.IsInterface;
try
{
Assembly assembly = Assembly.LoadFile(assemblyPath);
List<Type> types = new List<Type>();
Module[] modules = assembly.GetModules(false);
foreach (Module m in modules)
{
Type[] t =m.GetTypes();
foreach (Type i in t)
if (IsImplemented(i, typeOfParam))
types.Add(i);
}
List<T> objs = new List<T>();
foreach (Type type in types)
{
try
{
T o = (T)type.Assembly.CreateInstance(type.FullName);
objs.Add(o);
}
catch { } //此处抛出异常
}
return objs.ToArray();
}
catch
{
return new T[0];
}
}
要获取的类:
public class MSPPTPlayer:MediaPlayer
{
AxSHDocVw.AxWebBrowser webBrowserControl = new AxSHDocVw.AxWebBrowser(); Microsoft.Office.Interop.PowerPoint.Presentation document;
//... Other code
}
调用方部分代码:
System.Collections.ArrayList list= new System.Collections.ArrayList(System.IO.Directory.GetFiles(path, "*.dll"));
list.AddRange(System.IO.Directory.GetFiles(path,"*.exe"));
List<MediaPlayer> result = new List<MediaPlayer>();
for (int i =0;i<list.Count;i++)
{
Object o = list[i];
MediaPlayer[] found = Utility.GetImplementations<MediaPlayer>(o.ToString());
result.AddRange(found.ToList<MediaPlayer>());
}
在此请教各位大师, 这是什么原因? 应该如何解决? 小弟先行谢过.