Bug in AGHost ... Unassigned ErrorHandler

Is there a bug in agHost.js where it doesn't properly assign the errorHandler if errorHandler is null.

The code is

function agHost(hostElementId, id, width, height, backgroundColor, sourceElement, source, isWindowlessMode, framerate, errorHandler, reqMajorVer, reqMinorVer, reqBuildVer)
{
var agHostHelper = new Object();

agHostHelper.uaString = navigator.userAgent;
agHostHelper.hostElementId = hostElementId;
agHostHelper.id = id;
agHostHelper.width = width;
agHostHelper.height = height;
agHostHelper.backgroundColor = backgroundColor;
agHostHelper.sourceElement = sourceElement;
agHostHelper.source = source;
agHostHelper.isWindowlessMode = isWindowlessMode;
agHostHelper.framerate = framerate;

// if not set, the version defaults to "0.8.5.0"
agHostHelper.reqMajorVer = (reqMajorVer != null) ? reqMajorVer : 0;
agHostHelper.reqMinorVer = (reqMinorVer != null) ? reqMinorVer : 8;
agHostHelper.reqBuildVer = (reqBuildVer != null) ? reqBuildVer : 5;

// assign error handler
if(errorHandler == null)
{
errorHandler = function(line, column, errorCode, errorstring)
{
if(line != 0 && column != 0)
{
var errorString = "(" + line + "," + column + "): " + errorstring + "\n";
errorString += "ERROR CODE: " + errorCode;
alert(errorString);
}
}
}
else
{
agHostHelper.errorHandler = errorHandler;
}
...
}

So if errorHandler is null and the closure needs to be defined, it's never assigned to the property "errorHandler" hanging off of the agHostHelper object.

Am I missing something or should the "agHostHelper.errorHandler = errorHandler" statement not be inside the else? I'm just reading through the JS, I haven't even instantiated the JS closure yet.

Thx, Joel

[1925 byte] By [JayRu] at [2007-12-31]
# 1

I think this is definitely a bug exactly as you describe. If you look further down in the agHost.js file you will see the code (in the function buildHTMLForIE):

function buildHTMLForIE(agHostHelper)
{
var wpfePluginHTML = '<object id="'+agHostHelper.id+'" width="'+agHostHelper.width+'" height="'+agHostHelper.height+'"
classid="CLSID:32C73088-76AE- 40F7-AC40-81F62CB2C1DA">'
;
if (agHostHelper.sourceElement != null)
{
wpfePluginHTML += ' <param name="SourceElement" value="'+agHostHelper.sourceElement+'" />';
}

if (agHostHelper.source != null)
{
wpfePluginHTML +=
' <param name="Source" value="'+agHostHelper.source+'" />';
}

if (agHostHelper.framerate != null)
{
wpfePluginHTML +=
' <param name="MaxFrameRate" value="'+agHostHelper.framerate+'" />';
}

if (agHostHelper.errorHandler != null)
{
wpfePluginHTML += ' <param name="OnError" value="'+agHostHelper.errorHandler+'" />'
;
}

So you see in the test way above in the earlier post in the function agHost(...) that if ErrorHandler is null, then a global function called errorhandler will be created, but not assigned to the agHostHelper.errorHandler variable. So agHostHelper.Errorhandler will always be null, unless you explicitly supply your own. The global errorHandler function is essentially left dangling (and useless) and is never assigned to the OnError in the Object tag's OnError event.

I also recall very early posts when CTP 2 just came out about errors no longer working. This is why.

Kevgor at 2007-9-7 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...
# 2
Well I'm glad that somebody agrees with me. I'm so new to WPFE that I don't know where to submit bugs. Do we have a URL for that?
JayRu at 2007-9-7 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...
# 3
Yes this is a bug. Thank you for reporting this. This has now been fixed internally and the next release should carry the fix.
AshishShetty-MSFT at 2007-9-7 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) Developer Issues...