Silverlight 2 Error Code: 4004

Hi guys. I have a silverlight 2 application that has an ObservableCollection of a class from a separate / lib assembly. When I set my ListBox.ItemsSource in this collection and run it, I get the error code: 4004 "System.ArgumentException: value is not in the expected range". Here is the piece of 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 in the same project, everything works fine. Are there some safety things happening behind the scenes? Also, I use the html page generation option, not the aspx option, when I created this Silverlight 2 application.

+3
source share
2 answers

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

Since Silverlight 2 uses a subset of the CLR, it cannot access libraries of standard classes that have been 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 includes only the namespaces available for Silverlight and allow you to reference the assembly in the Silverlight project.

For more information, see the MSDN article, ".NET Framework Class Library for Silverlight . "

+1
source

Perhaps this is because you are not handling the failure in SubmittedChanges (). See http://www.scottleckie.com/2010/04/code-4004-unhandled-error-in-silverlight-application/ for more information

0
source

All Articles