views:

2410

answers:

2

Hey guys/gals. I have a silverlight 2 app that has an ObservableCollection of a class from a separate assem/lib. When I set my ListBox.ItemsSource on that collection, and run it, I get the error code: 4004 "System.ArgumentException: Value does not fall within the expected range." Here is part of the code:

public partial class Page : UserControl
{
    ObservableCollection<Some.Lib.Owner> ooc;

    public Page()
    {

        ooc = new ObservableCollection<Some.Lib.Owner>();
        Some.Lib.Owner o1 = new Some.Lib.Owner() { FirstName = "test1" };
        Some.Lib.Owner o2 = new Some.Lib.Owner() { FirstName = "test2" };
        Some.Lib.Owner o3 = new Some.Lib.Owner() { FirstName = "test3" };
        ooc.Add(o1);
        ooc.Add(o2);
        ooc.Add(o3);

        InitializeComponent();
        lb1.ItemsSource = ooc;
    }
}

But when I create the Owner class within this same project, everything works fine. Is there some security things going on behind the scenes? Also, I'm using the generate a html page option and not the aspx option, when I created this Silverlight 2 app.

+1  A: 

Are you trying to use a standard class library or a "Silverlight Class Library"?

Because Silverlight 2 uses a subset of the CLR it cannot access standard class libraries that were compiled using the full CLR. To use an external assembly you must create it as a "Silverlight Class Library". This will create a project that only includes the namespaces available to Silverlight and will allow you to reference the assembly within your Silverlight project.

Check out the MSDN article ".NET Framework Class Library for Silverlight" for more info.

AJ
Yeah, I created it as a Silverlight Class Library. After countless hours searching "The Google", I just gave up. Everything is in one project now.
jkidv
A: 

It may be because you're not handling a failure in SubmittedChanges(). See http://www.scottleckie.com/2010/04/code-4004-unhandled-error-in-silverlight-application/ for more info

Scott Leckie