Print Page | Close Window

IdeaBlade.Core.TraceFns throws System.TypeInitializationException in WinForm Client

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1732
Printed Date: 06-Jun-2024 at 8:29am


Topic: IdeaBlade.Core.TraceFns throws System.TypeInitializationException in WinForm Client
Posted By: sebma
Subject: IdeaBlade.Core.TraceFns throws System.TypeInitializationException in WinForm Client
Date Posted: 20-Apr-2010 at 11:33pm
With reference to
http://www.ideablade.com/forum/forum_posts.asp?TID=1528&KW=TraceFns - http://www.ideablade.com/forum/forum_posts.asp?TID=1528&KW=TraceFns
 
IdeaBlade.Core.TraceFns throws System.TypeInitializationException just by having the following codes in in WinForm Client program's Main entry:
 
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
    IdeaBlade.Core.TraceFns.WriteLine("Hello");
 
System.TypeInitializationException: The type initializer for 'IdeaBlade.Core.TraceFns' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at IdeaBlade.Core.TraceFns.StackWriteLine(StackFrame pStackFrame, String pMessage)
   at IdeaBlade.Core.TraceFns.StackWriteLineIf(Boolean pCondition, String pMessage)
   at IdeaBlade.Core.TraceFns.WriteLine(Object value)
   at IdeaBlade.Core.AuthHelper.LoadRuntimeLicense(Action`1 errorCallback)
   at IdeaBlade.Core.IdeaBladeConfig.Initialize()
   at IdeaBlade.Core.IdeaBladeConfig.get_Instance()
   at IdeaBlade.Core.TraceFns.Initialize()
   at IdeaBlade.Core.TraceFns..cctor()
 
Remove the above line and WinForm Client works as usual, IdeaBlade logs written to:
<logging logFile="DebugLog.xml" />
 
I am still using DevForce v.5.2.3.1, server-side has no such problem. With DevForce supporting SilverLight clients now, is it now not possible to use IdeaBlade.Core.TraceFns in WinForm Client too?
 
Thanks
Sebastian
 
 
 
http://www.ideablade.com/forum/forum_posts.asp?TID=1528&KW=TraceFns -  



Replies:
Posted By: kimj
Date Posted: 21-Apr-2010 at 10:37am
Hi Sebastian,
 
You can definitely use tracing from WinClient applications.  That unfortunate exception is due to a kind of race condition at startup -- TraceFns.WriteLine needs the TraceFns static class initialized, which in turn needs the IdeaBladeConfig.Instance loaded.  We're not correctly detecting this, or controlling initialization sequence, so you get this ugly error.
 
There's an easy workaround, however, and is what we actually do automatically in the server-side code (for slightly different reasons) -- just call the following before the TraceFns.WriteLine call:
 
  IdeaBlade.Core.IdeaBladeConfig.AssertNonDefaultVersion();
 
This will ensure that the IdeaBladeConfig is initialized, and you can then use TraceFns normally.



Print Page | Close Window