Solved

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

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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
I couldnt select James answer as that didnt answer this particular question.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

771 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

10 Experts available now in Live!

Get 1:1 Help Now