SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in

1,855 views
Skip to first unread message

Simon Sutherill

unread,
Nov 19, 2012, 9:53:06 AM11/19/12
to nlog-...@googlegroups.com

My WindowsForms application is not compiling.  The error is as follows:
InvalidOperatinException was unhandled: SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.

It works without issue when I comment out the richtextbox (outputbox) in the nlog.config (see below).  Any ideas?
 
Program.cs:
using System.Linq;
using System.Windows.Forms;
using NLog;



namespace SQLSMODemo
{
   
static class Program
   
{
       
private static Logger logger = LogManager.GetCurrentClassLogger();
       
/// <summary>
       
/// The main entry point for the application.
       
/// </summary>
       
[STAThread]
       
static void Main()
       
{
            logger
.Trace("Sample trace message");
           
Application.EnableVisualStyles();
           
Application.SetCompatibleTextRenderingDefault(false);
           
Application.Run(new Form1());
       
}
   
}
}

Nlog.config:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
     
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 
<!-- make sure to set 'Copy To Output Directory' option for this file -->
 
<!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->
 
<targets>
   
<target name="logfile" xsi:type="File" fileName="c:\temp\file.txt" />
   
<target xsi:type="RichTextBox" name="outputbox" layout="${longdate}|${level:uppercase=true}|${logger}|${message}" controlName="richTextBox1" formName="Form1" />
 
</targets>
 
<rules>
   
<logger name="UI" minlevel="Trace" writeTo="outputbox" />
   
<logger name="*" minlevel="Trace" writeTo="logfile" />
 
</rules>
</nlog>
I am 100% sure this is me ... I just don't why or how ... any assistance would be great.
 

Jason LaFlair

unread,
Nov 19, 2012, 10:34:57 AM11/19/12
to nlog-...@googlegroups.com
Change your Main to do what the error message is saying :)

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
logger.Trace("Sample trace message");
Application.Run(new Form1());


 

--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To post to this group, send email to nlog-...@googlegroups.com.
To unsubscribe from this group, send email to nlog-users+...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages