所以我试图在单元测试中调用构造函数:
MainWindow window = new MainWindow();
但是,这会导致MainWindow constrcutor的InitializeComponent方法中出现以下错误:
System.windows.Markup.XamlParseException occurred Message='ProvIDe value on 'System.windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' line number '9' and line position '42'. Source=PresentationFramework lineNumber=9 lineposition=42 StackTrace: at System.windows.Markup.XamlReader.RewrapException(Exception e,IXamllineInfo lineInfo,Uri baseUri) InnerException: System.IO.IOException Message=Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack://application:,/assemblyname;component/ Syntax to specify the assembly to load the resource from. Source=PresentationFramework StackTrace: at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(Uri uri,String& partname,Boolean& isContentfile) at MS.Internal.AppModel.ResourceContainer.GetPartCore(Uri uri) at System.IO.Packaging.Package.GetPartHelper(Uri partUri) at System.IO.Packaging.Package.GetPart(Uri partUri) at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.get_ContentType() at System.windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri,Stream stream,BitmapCacheOption cacheOption,GuID& clsID,Boolean& isOriginalWritable,Stream& uriStream,UnmanagedMemoryStream& unmanagedMemoryStream,SafefileHandle& safefilehandle) at System.windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri,Uri uri,BitmapCreateOptions createOptions,RequestCachePolicy uriCachePolicy,Boolean insertInDecoderCache) at System.windows.Media.Imaging.BitmapFrame.CreateFromUriOrStream(Uri baseUri,RequestCachePolicy uriCachePolicy) at System.windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context,CultureInfo culture,Object value) at System.windows.Baml2006.TypeConverterMarkupExtension.ProvIDeValue(IServiceProvIDer serviceProvIDer) at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvIDeValue(MarkupExtension me,IServiceProvIDer serviceProvIDer) InnerException:解决方法 尝试以下:
if(Application.ResourceAssembly == null) Application.ResourceAssembly = typeof(MainWindow).Assembly;var window = new MainWindow();总结
以上是内存溢出为你收集整理的c# – 如何实例化或模拟窗口编程?全部内容,希望文章能够帮你解决c# – 如何实例化或模拟窗口编程?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)