Solved

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

Posted on 2014-07-27
3
517 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now