Silverlight TDD测试项目通过Reflector加载类型异常
异常消息:Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
被测项目(MathEngine)是Silverlight窗体项目,
MathEngine.App和MathEngine.MainPage分别是默认的应用程序类和主窗体类,因此包含了System.Windows的引用。
而测试项目(MathEngineTests)默认为非窗体项目,并没有添加对System.Windows的引用。
添加引用:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll,
该问题得以解决!
public static IEnumerable<T> CreateInstances<T>() { try { Type basic = typeof (T); var types = basic.Assembly.GetTypes(); var result = (from t in types where basic.IsAssignableFrom(t) && !t.IsAbstract //&& !t.HasAttribute<IgnoreAttribute>() select (T) Activator.CreateInstance(t)).ToList(); return result; } catch (ReflectionTypeLoadException ex) { //测试项目(MathEngineTests)无法加载:MathEngine.App和MathEngine.MainPage两种类型 //需要添加引用:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll throw ex; } catch (Exception ex) { throw ex; } }
浙公网安备 33010602011771号