Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-07-27
3
Medium Priority
?
587 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
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.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

722 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