Silverlight Error Codes Explained! 20. July 2007 Game Development, Reviews Comment (1) Side note: FX Composer 2 RC1 is out. Check it out, works even better now.I worked a bit with Silverlight 1.1 (alpha) over the last few weeks and I noticed a lot of annoyingjavascript error messages with just stupid error codes and no stack trace for the exceptions.This is definately the worst thing about Silverlight, you have to do a lot of trial and error testing,unit testing and debugging silverlight is also hard to do.I wrote down all the errors I have encountered and some solutions to them, which might behelpful to other people coding Silverlight too. Now whenever I get an error I just look into thislist and follow the steps from top to bottom and this way I save a lot of time ^^ maybe I willalso rewrite the javascript on_error code that throws these errors to a more useful version.Silverlight Error Codes:1001: usually AG_E_UNKNOWN_ERROR (yeah, thats really helpful)some element is null while loading a controlFix: Check all controls constructors and fields, set breakpoints there!Namespace duplicate found (usually error code 2254)Fix: Check all namespaces, make sure each name and namespace is only set onceControl has no default Constructor and can't be instantiatedFix: Provide a default constructor with no parameters, it can be empty!NullReferenceException (or other exceptions) happend somewhere(usually in the Control constructor somewhere)Fix: Catch the exception or set breakpoints to find it, then fix it.Often it is also useful to comment code out and test if it works again.If this all not helps and the 1001 errors keeps coming up when you use the control use the following approach:Fix: Comment out the control, the page should now work.Comment it in again and check every single property you set, try removingas much as possible and test again. If it still does not work, check outthe control itself, comment everything out here inside the control canvas.It should work now except for some errors of missing inner control names. Now slowly comment everything in again and try to see which inner controldid not work. Often a depreciacted, commented out or deleted property is used and causes this error. Again try to work with as little as possible control properties and increase until the error pops up again. This more complex case will hopefully not happen to you in the beginning,but the more controls you build, the more likely it is that this onewill annoy the hell out of you. Keep calm and go forward as methodicallyas possible, it will also help you for future error encounters. Can happen if a TargetName for a Storyboard (or something similar) cannotbe found. Make sure the target control name is still valid.2005: ParserError: Unknown namespace xyThe line should tell you which namespace is unknown and this shouldbe quite easy to fix. It usually means you have either forgotten toadd a namespace or add an element into an unsupported location.E.g. adding something to a nested Canvas can sometimes cause this error.2024: ParserError:Invalid attribute value text/python, usually happens in the main xaml file.Similar to 2265, use the same fixes.It can also happen when the mime typeis not available (e.g. in IIS) and .py files can't be used.Fix: Define .py as mime type in IIS as 'text/ironpython' 2101: can be:LostFocus event (or similar) not supported hereFix: Move global events to the main canvas, they are only supported there!2207: AG_E_RUNTIME_METHODplaying media failed, unable to play it, loading probably failed with 403or 4042210: AG_E_INVALID_ARGUMENTShort: In 90% of your cases the embedded resource cannot be found, makesure that the name of your embedded resource is correct in theGetManifestResourceStream function in your control constructor. Also makesure the file is marked as an embedded resource in VS Orcas!This means the embedded resource could not be found, which means either thecall to GetManifestResourceStream uses the wrong string OR the resourceis just not existant because of a wrong content type! make sure thecontrol you are trying to access is actually an Embedded Resource and notjust a Content or Silverlight Page.Fix: Set control xaml as Embedded Resource and make sure all strings arecorrect! GetManifestResourceStream should succeed! Using the Silverlight1.1 API UI Controls is also helpful because they figure out the pathfor you (just leaving you with misstyping the control name or forgettingto set the embedded resource type or one of the million errors below).Note: This is very annoying because SourceControl sometimes messes this upand just merges 2 files and setting it as Content or Silverlight Page,which make this error hard to track, so always check for the correctfile build action first, it should always be Embedded Resource for controls. Another way this error can happen is when inside the control a namespaceerror occurs (similar to 1001 or 2254), you just get 2210 and trying tofind why it does not work while all names are set ok and the resource isfound, etc. One example of this failing is that a namespace or assemblyused inside a control to reference other controls cannot be found or ismisspelled (e.g. path does not longer fit, can be stupid things likeClientBin/Some.dll should be ../ClientBin/Some.dll)Fix: Check all namespaces in the control too, make sure all names arecorrect and files (especially assemblies) can be found the way theyare specified!Advanced Fix: I use reflection to find out about the class name and usethat same name for the .xaml file, this way I never have to specifyany name and merging files does not lead to problems as long as the xamlfile has the same name as the class (which is easy to spot in VS Orcas).Another VERY crazy way for this to happen is when one of your controls isusing the partial keyword for its control class and overwrites some of theautogenerated background fields (through x:Class in the main Canvas of thecontrol), it is probably better to always remove the partial and make surethe control is all managed by you (like in the SDK samples).Fix: Remove the partial in c# and the x:Class in xaml if you get compileerrors, after that it usually just works :)Older notes (before I figured this out):Seems to happen with perfectly fine xaml code, no c# breakpoint is everhit, so this must happen while parsing the xaml. Often also changes to error2254 if some name or namespace is wrong, but then gets back to 2210 if thatis fixed.Someone here traced the 2210 back to “InitializeFromXaml” being calledwith an invalid resource stream (GetManifestResourceStream), which failedone line above it:http://silverlight.net/forums/t/1755.aspx 2251: ParserError, AG_E_RUNTIME_MANAGED_ACTIVATIONProbably a security issue, seems to happen on a Max when the xaml filecould not be loaded or accesses something that is not available (assemblies)Fix: Seems to be a Mac bug, will hopefully be fixed in the future. 2252: can be:Canvas Load Error, canvas could not be loaded because something is wrongit may help to check out the line and error description for more details.Fix: Look through the xaml line by line, annoying, but something is wrongAG_E_RUNTIME_MANAGED_ASSEMBLY_DOWNLOAD:When this happens the control at the line specified failed to load.This can be because it crashed somewhere in the constructor, setting abreakpoint usually tells you wether it crashed in C# or already in thexaml. If it is in the xaml, you have to figure out the error there (tryto uncomment, check namings, etc.). If it happens in C# setting abreakpoint makes it much easier, but the error is still annoying. Forthat reason you should make sure to test your controls as much aspossible before using them on a complex page.Fix: Set a breakpoint in the constructor of the control and fix theexception! Or if that does not help, take a close look at the xamland comment it out to see what works and what does not.More help about 2252 from http://silverlight.net/forums/t/370.aspxAssembly loading failed, this can happen because of the IIS beingmisconfigured (unlikely if you doing development) or because thepath to the assembly could not be found (much more likely).Fix: Make sure both the page xaml and the control xaml point to thecorrect directory for the dll and make sure this works from theperspective of the page, not the directories the xaml files are in!In my case changing ClientBin/.dll to ../ClientBin/.dll often didthe trick!Another issue can happen when you rename the assembly, but not all the.dll links are correct. It can also be problematic if there are specialletters like - in the assembly, which will get renamed to _, but thefilename is still with -, see here:http://silverlight.net/forums/t/370.aspxFix: Just check all .dll links and make sure both the name and the pathare correct. 2254: AG_E_RUNTIME_MANAGER_ASSEMBLY_DOWNLOAD, can be:Control type not found because a namespace is not set correctly, this canhappen if you just copy a file from another project and do not change thenamespace accordingly.Fix: Make sure all namespaces are correct (same in xaml as in the controls)Namespace duplicate found, make sure that all namespaces and names onlyoccur once.Fix: See above 1001 2255: AG_E_PARSER_BAD_TYPEAn unsupported type was found, which usually means you are specifying acontrol or class for the xaml, which does not exist (anymore). Make surethat the x:Class parameter points to an existing class and uses a correctnamespace.Also seems to happen when there are multiple comment blocks mixed in thexaml file or some name contains an invalid character because of that.Clear the xaml file and test until it works again, then insert the removedcode again to figure out where the error is happening. The line/positioninformation of this error is usually not very helpful! 2265: Error: Parser codeParsing xaml failed, this has been reported after saving some xaml in Blendbut it could not be parsed in Visual Studio.Fix: Try using only parts of the xaml, use smaller files, dunno.Parsing xmal failed, some syntax error.Fix: You should be able to spot the error and fix it if it is a smallerfile, for bigger files comment most of it out and comment it back in untilit breaks again. Then fix the issue.3001: AG_E_INVALID_FILE_FORMATOften a ImageError, which usually means you are trying to load anunsupported image format like the .GIF format, which is not supportedby Silverlight yet.Fix: Use .PNG instead of .GIF, etc. 3002: AG_E_NOT_FOUND:Error type should describe which kind of resource was not found (usuallyImageError). Check your constructor and Page_Loaded methods and checkall the files that are loaded there and make sure they exist. This isprobably the equivalent of FileNotFoundException, just all the helpfulinformation (which file, why, etc.) is missing. Sometimes the error type isconfusing because it may report an ImageError, but in reality just the xamlfile could not be loaded, always check the xaml file (name, loading, etc.)! 3010: can be:Silverlight installation is not complete yet, restart browser (or computerif this error persists).Fix: Tell user to restart browser.Link to the silverlight.net forum (post this here too), 13 known issueswith Silverlight 1.1. It is good to know them:http://silverlight.net/forums/t/2400.aspxOther helpful links:http://blogs.conchango.com/stevenevans/archive/2007/06/06/Silverlight-Adventures-with-Blend.aspxhttp://www.thescripts.com/forum/thread650457.htmlhttp://silverlight.org/forums/t/1422.aspxNote: I will add more errors to this list for Silverlight 1.1 alpha, but I will probably justwrite a new blog entry for newer Silverlight versions. Still pretty excited about the newVS Orcas Beta 2 release ^^