Solved

Need Help : The type initializer for 'System.Windows.Media.Brush' threw an exception.

Posted on 2014-07-27
3
527 Views
Last Modified: 2014-08-17
Hello,

When i try to export a report in excel from our product (uses .net framework 4.5.2) i get the following error and also found the link corresponding to it based on it inner stack trace but do not know what to do. Any help will be highly appreciated

http://forums.asp.net/t/1982501.aspx?System+ComponentModel+Win32Exception+The+system+cannot+find+the+file+specified

Detailed error messages
---------------------------------

Type: System.TypeInitializationException
Message: The type initializer for 'System.Windows.Media.Brush' threw an exception.
Source: PresentationCore
Stacktrace:    at System.Windows.Media.KnownColors.SolidColorBrushFromUint(UInt32 argb)
   at IDV.OpenXml.SpreadsheetML.TextMeasurer.MeasureNoWrap(String text)
   at IDV.OpenXml.SpreadsheetML.WorksheetColumnInfo.MeasureMaxmimumDigitWidth(String fontName, Double fontSize, Boolean isBold, Boolean isItalic)
   at IDV.OpenXml.SpreadsheetML.WorksheetColumnInfo.GetDefaultStyleMaximumDigitWidth(Workbook workbook)
   at IDV.OpenXml.SpreadsheetML.Writing.WorksheetWriter.GetColInfoFromColumnInfo(WorksheetColumnInfo info)
   at IDV.OpenXml.SpreadsheetML.Writing.WorksheetWriter.WriteColumns(PartXmlWriter xmlWriter, Worksheet sheet)
   at IDV.OpenXml.SpreadsheetML.Writing.WorksheetWriter.SavePartContentCore(PartRelationshipWriter relationshipWriter, PartXmlWriter xmlWriter, Object partData)
   at IDV.OpenXml.Core.XmlPartContentWriter.SavePartContent(PartRelationshipWriter relationshipWriter, Stream output, Object partData)
   at IDV.OpenXml.Core.PackageWriter.WritePartContent(Object partData, String partName, IPartContentWriter contentWriter)
   at IDV.OpenXml.Core.PackageWriter.WriteQueuedParts()
   at IDV.OpenXml.Core.PackageWriter.WriteRelatedPart(PartRelationshipWriter parentWriter, Object partData, String relationshipType, String partNameFormat, String partContentType, IPartContentWriter contentWriter)
   at IDV.OpenXml.SpreadsheetML.Writing.ExcelFileWriter.Save(Workbook workbook, Stream output)
   at iSOS.TravelTracker.Module.Server.Service.ExcelHelper.GetExcelWorkbook(String searchType, DataTable itineraries, Int32 customerId, String membershipType, Boolean isEmulatedCustomerData)
   at iSOS.TravelTracker.Module.Server.Service.ExcelHelper.RunExcelReport(Object paramsToGetItineraries)
  Inner Exception Found:
  Type: System.TypeInitializationException
  Message: The type initializer for 'System.Windows.Media.Transform' threw an exception.
  Source: PresentationCore
  Stacktrace:    at System.Windows.Media.Brush..cctor()
    Inner Exception Found:
    Type: System.ComponentModel.Win32Exception
    Message: The system cannot find the file specified
    Source: WindowsBase
    Stacktrace:    at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
   at System.Windows.Threading.Dispatcher..ctor()
   at System.Windows.DependencyObject..ctor()
   at System.Windows.Media.Transform..cctor()
0
Comment
Question by:Star79
  • 2
3 Comments
 
LVL 40
ID: 40223403
Give a look at the documentation for System.Windows.Media: Provides types that enable integration of rich media, including drawings, text, and audio/video content in Windows Presentation Foundation (WPF) applications

You are not dealing with a WPF application, you are dealing with Excel.

Although color values are interchangeable between different types of applications, the ways you access these values are not the same. You do not use a System.Windows.Media.Brush when you work in a Windows application, you use a System.Drawing.Brush. Even more so when you are using an external application such as Excel, that does not use the same standards as .NET. You need to pass the colors the way Excel expects them, not the way you use them internally in the .NET application.

Not seeing the code that generates the error, it's hard to be specific, and I do not have much experience with OpenXML anyway. But there should be something in the OpenXML documentation that tells you what it expects for color values. Directly in Excel for instance, to have the background of a cell in red, I would simply pass set the Interior.ColorIndex property of the cell to 3. I would definitely not a use any of the Brush objects from the framework.
0
 

Accepted Solution

by:
Star79 earned 0 total points
ID: 40256365
This issue was with too much traffic coming to one server and the servers not were not load balanced. Restarting the app pool has fixed the issue. Well it may be inefficient coding but didnt get a chance to find the root cause when restarting the pool helped and included some preventative measures. Thanks James for your answer.
0
 

Author Closing Comment

by:Star79
ID: 40265948
I couldnt select James answer as that didnt answer this particular question.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question