Delta Engine Blog

AI, Robotics, multiplatform game development and Strict programming language

Silverlight Error Codes Explained!

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 annoying
javascript 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 be
helpful to other people coding Silverlight too. Now whenever I get an error I just look into this
list and follow the steps from top to bottom and this way I save a lot of time ^^ maybe I will
also 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 control
    Fix: 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 once

  • Control has no default Constructor and can't be instantiated
    Fix: 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 removing
    as much as possible and test again. If it still does not work, check out
    the 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 control
    did 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 one
    will annoy the hell out of you. Keep calm and go forward as methodically
    as possible, it will also help you for future error encounters.
  • Can happen if a TargetName for a Storyboard (or something similar) cannot
    be found. Make sure the target control name is still valid.

  • 2005:    ParserError: Unknown namespace xy
  • The line should tell you which namespace is unknown and this should
    be quite easy to fix. It usually means you have either forgotten to
    add 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 type
    is 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 here
    Fix: Move global events to the main canvas, they are only supported there!

  • 2207: AG_E_RUNTIME_METHOD
  • playing media failed, unable to play it, loading probably failed with 403
    or 404

  • 2210: AG_E_INVALID_ARGUMENT
  • Short: In 90% of your cases the embedded resource cannot be found, make
    sure that the name of your embedded resource is correct in the
    GetManifestResourceStream function in your control constructor. Also make
    sure the file is marked as an embedded resource in VS Orcas!
  • This means the embedded resource could not be found, which means either the
    call to GetManifestResourceStream uses the wrong string OR the resource
    is just not existant because of a wrong content type! make sure the
    control you are trying to access is actually an Embedded Resource and not
    just a Content or Silverlight Page.

    Fix: Set control xaml as Embedded Resource and make sure all strings are
    correct! GetManifestResourceStream should succeed! Using the Silverlight
    1.1 API UI Controls is also helpful because they figure out the path
    for you (just leaving you with misstyping the control name or forgetting
    to set the embedded resource type or one of the million errors below).

    Note: This is very annoying because SourceControl sometimes messes this up
    and just merges 2 files and setting it as Content or Silverlight Page,
    which make this error hard to track, so always check for the correct
    file build action first, it should always be Embedded Resource for controls.
  • Another way this error can happen is when inside the control a namespace
    error occurs (similar to 1001 or 2254), you just get 2210 and trying to
    find why it does not work while all names are set ok and the resource is
    found, etc. One example of this failing is that a namespace or assembly
    used inside a control to reference other controls cannot be found or is
    misspelled (e.g. path does not longer fit, can be stupid things like
    ClientBin/Some.dll should be ../ClientBin/Some.dll)

    Fix: Check all namespaces in the control too, make sure all names are
    correct and files (especially assemblies) can be found the way they
    are specified!

    Advanced Fix: I use reflection to find out about the class name and use
    that same name for the .xaml file, this way I never have to specify
    any name and merging files does not lead to problems as long as the xaml
    file 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 is
    using the partial keyword for its control class and overwrites some of the
    autogenerated background fields (through x:Class in the main Canvas of the
    control), it is probably better to always remove the partial and make sure
    the 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 compile
    errors, 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 ever
    hit, so this must happen while parsing the xaml. Often also changes to error
    2254 if some name or namespace is wrong, but then gets back to 2210 if that
    is fixed.
  • Someone here traced the 2210 back to “InitializeFromXaml” being called
    with an invalid resource stream (GetManifestResourceStream), which failed
    one line above it:
    http://silverlight.net/forums/t/1755.aspx
    
  • 2251: ParserError, AG_E_RUNTIME_MANAGED_ACTIVATION
  • Probably a security issue, seems to happen on a Max when the xaml file
    could 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 wrong
    it 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 wrong
  • AG_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 a
    breakpoint usually tells you wether it crashed in C# or already in the
    xaml. If it is in the xaml, you have to figure out the error there (try
    to uncomment, check namings, etc.). If it happens in C# setting a
    breakpoint makes it much easier, but the error is still annoying. For
    that reason you should make sure to test your controls as much as
    possible before using them on a complex page.

    Fix: Set a breakpoint in the constructor of the control and fix the
    exception! Or if that does not help, take a close look at the xaml
    and comment it out to see what works and what does not.
  • More help about 2252 from http://silverlight.net/forums/t/370.aspx
    Assembly loading failed, this can happen because of the IIS being
    misconfigured (unlikely if you doing development) or because the
    path to the assembly could not be found (much more likely).

    Fix: Make sure both the page xaml and the control xaml point to the
    correct directory for the dll and make sure this works from the
    perspective of the page, not the directories the xaml files are in!
    In my case changing ClientBin/.dll to ../ClientBin/.dll often did
    the 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 special
    letters like - in the assembly, which will get renamed to _, but the
    filename is still with -, see here:
    http://silverlight.net/forums/t/370.aspx

    Fix: Just check all .dll links and make sure both the name and the path
    are correct.
        
  • 2254: AG_E_RUNTIME_MANAGER_ASSEMBLY_DOWNLOAD, can be:
  • Control type not found because a namespace is not set correctly, this can
    happen if you just copy a file from another project and do not change the
    namespace 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 only
    occur once.
    Fix: See above 1001
        
  • 2255: AG_E_PARSER_BAD_TYPE
  • An unsupported type was found, which usually means you are specifying a
    control or class for the xaml, which does not exist (anymore). Make sure
    that the x:Class parameter points to an existing class and uses a correct
    namespace.
  • Also seems to happen when there are multiple comment blocks mixed in the
    xaml file or some name contains an invalid character because of that.
    Clear the xaml file and test until it works again, then insert the removed
    code again to figure out where the error is happening. The line/position
    information of this error is usually not very helpful!
        
  • 2265: Error: Parser code
  • Parsing xaml failed, this has been reported after saving some xaml in Blend
    but 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 smaller
    file, for bigger files comment most of it out and comment it back in until
    it breaks again. Then fix the issue.

  • 3001: AG_E_INVALID_FILE_FORMAT
  • Often a ImageError, which usually means you are trying to load an
    unsupported image format like the .GIF format, which is not supported
    by 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 (usually
    ImageError). Check your constructor and Page_Loaded methods and check
    all the files that are loaded there and make sure they exist. This is
    probably the equivalent of FileNotFoundException, just all the helpful
    information (which file, why, etc.) is missing. Sometimes the error type is
    confusing because it may report an ImageError, but in reality just the xaml
    file could not be loaded, always check the xaml file (name, loading, etc.)!
        
  • 3010: can be:
  • Silverlight installation is not complete yet, restart browser (or computer
    if this error persists).
    Fix: Tell user to restart browser.

Link to the silverlight.net forum (post this here too), 13 known issues
with Silverlight 1.1. It is good to know them:
http://silverlight.net/forums/t/2400.aspx

Other helpful links:
http://blogs.conchango.com/stevenevans/archive/2007/06/06/
Silverlight-Adventures-with-Blend.aspx

http://www.thescripts.com/forum/thread650457.html
http://silverlight.org/forums/t/1422.aspx

Note: I will add more errors to this list for Silverlight 1.1 alpha, but I will probably just
write a new blog entry for newer Silverlight versions. Still pretty excited about the new
VS Orcas Beta 2 release ^^