Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-07-27
3
Medium Priority
?
617 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

824 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