Thursday, 7 April 2011

ReportViewer - object datasource, nested objects return #Error

If you are using Visual studio 2010 and Report viewer you may have experienced the problem with using Nested Properties on the report with the fields returning #Error.

This has been fixed in Service Pack 1 for Visual studio 2010 although you must ensure all classes referenced in the report have the [Serializable] attribute for EVERY property that is a user type, they must also be a public class, and also a public constructor with no parameters. Without these you will still get the error. When a class is serialized it cannot be unserialized without the Default constructor as the class is instanitated with that constructor, then the properties set once the class is created. It also seems that if the entire class cannot be serialized the report will not show it.

To use a nested property on the report the following expression should be entered:

=Fields!Supplier.Value.SupplierLocation.Address1

This expression adds a field to the report that is three properties deep from the object the report is bound to.

The report datasource binds to an Order class, the order class contains a Supplier property, and the Supplier class contains a Supplier Location Property.

The Order, Supplier and Supplier Location class must use the [Serializable] attribute, and also any other property of any of the classes referenced. eg, Just make every class in your project Serializable and you should be good to go. ( technically you dont need every class but this was easier than checking every property of each nested object to make sure its serializable.

eg:


UPDATE: 16/06/2011

I tried to do another report with a different object and the #Error problem returned. However, After going though every single property that is a class in my datasource, and adding the serializable attribute to the report started working again. So, Every property of the object needs to be serializable, otherwise it seems the whole object cannot be serialized.

Checklist:
  • ALL classes are serializable (every user type in the class must be serializable, and any user type in a property of a usertype must be serialzable)
  • ALL classes have a public parameterless constructor
  • ALL classes used in the report must have the public modifier
  • If any property of the datasource, or any property of a property cannot be serialized then your will get the #Error. Just make sure everything is serializable
  • Make sure there will be no infinite recursion issues - eg, class A has a property of class B, and class B has a property of class A. Use XMLIgnore / ScriptIgnore attributes

UPDATE: 22/06/2011

Sample project can now be downloaded from

Sample Web Project

77 comments:

  1. I have VS2010 SP1 installed. I have tagged all applicable classes with [Serializable], and still no love.

    After you got it set up correctly, when you were editing your expression, did intellisense show SupplierLocation after you type Value.?

    My members are not coming up in intellisense, and when I type them manually, they get red squiggly lines. Does that go away after you're set up correctly?

    ReplyDelete
    Replies
    1. Hi Carson,

      Intellisense is not working for me either, and I too get the red underline on the last property of the query.

      What syntax do you have for your field?

      I just copied this from my report which is working at the moment;

      =Fields!SYSCompanyLocation.Value.AddressLine1

      This is accessing a property from my 'Order' object. If I was accessing this in C# code then it would be:

      this.Order.SYSCompanyLocation.Address1

      Delete
  2. I have VS2010 with SP1 and I get #Error in the reports.
    How do you get serialization?
    I do this:

    < Serializable() > _
    Partial Public Class Car
    End Class

    Is this correct?

    Thanks

    ReplyDelete
    Replies
    1. Hi Miguel,

      I just added the serializable attribute ([Serializable] in c#) to all of the classes. eg. for each property of the class you are trying to use in the report, check if the property is a class itself, and then make that class serializable. Repeat all the way down the inheritance structure.

      Hope that helps

      Delete
  3. @Miguel and Carson,

    I have updated my post with some more details. Specifically the requirement for a parameterless constructor which may have been an issue in your code. Parameterless constructors are required to re-serialize and object so this may be why the above is not working for you.

    ReplyDelete
  4. Hi Ice Coffee,

    I have created a sample project in which nested properties are working. The project link has been added as an update and can be downloaded from:

    https://sites.google.com/site/wraithnath/WraithNath.NestedProperties.Web.zip?attredirects=0&d=1

    ReplyDelete
  5. Many thanks for helping! But when using virtual properties the #error info appears again. Any sugestion?

    ReplyDelete
  6. @Anonymous - I just amended the same project so the Order class inherits from a new class called OrderBase with a virtual OrderID propery, then added an override to the order class and the report was still working. Can you try the same with the same project?

    Make sure your base class is serializable.

    eg:

    [Serializable]
    public class OrderBase
    {
    public virtual int OrderID { get; set; }

    public OrderBase()
    {

    }
    }

    [Serializable]
    public class Order : OrderBase
    {
    public DateTime OrderDate { get; set; }
    public Supplier Supplier { get; set; }

    public override int OrderID
    {
    get { return int.MinValue; }
    set { base.OrderID = value; }
    }

    public Order()
    {

    }
    }

    ReplyDelete
  7. Sorry, I explained the problem poorly. The #Error appears when the nested object have a virtual property. In my case, using EF 4.1.
    I am commenting as anonymous because I do not have any of these accounts.

    ReplyDelete
  8. Hi Anon,

    ok, I have changed my supplier class like so:

    [Serializable]
    public class Supplier
    {
    public virtual string SupplierName { get; set; }
    public virtual string SupplierAccountRef { get; set; }

    public Supplier()
    {

    }
    }

    this also still seems to work, I'm afraid I cant comment on whether it will work with EF as I have not used it. I can't think of a reason why a virtual property would make a difference though. Are all the EF classes serializable with a public parameterless constructor?

    ReplyDelete
  9. Thank you again. The problem is related to the creation of proxies in EF 4.1.
    After making the changes you suggested in the main topic, use the "Configuration.ProxyCreationEnabled = false;" of DbContext solved the problem, but also disables the Lazy Loading.

    ReplyDelete
  10. Hi, not a problem, Glad it helped :)
    Disabling the lazy loading might not be too much of a problem. I have had a lot of issues with sub reports or nested properties that are not preloaded as by the time the second request to the database is made the identity context has been lost and the report viewer can authenticate with SQL server (if you are using integrated security anyway)

    ReplyDelete
  11. I spent alot of time to find solution for this problem
    thank you so much

    ReplyDelete
  12. I built a Web Site with local reports (rdlc) in Visual Studio 2008, but recently moved to Visual Studio 2010 (with SP1) and ReportViewer 10. Most of my reports involve hierarchical data where my datasources are lists of objects with nested objects. All of my objects are serializable. The reports work fine on my development workstation, but I get #Error for the nested object properties when the reports are deployed to a Win2008 server with IIS7. I know SP1 fixed the issue in VS2010, so is there a similar patch that I need to install on the web server to get this to work?

    ReplyDelete
    Replies
    1. Hi,

      Thats right, you also need to install the ReportViewer for visual studio 2010 SP1 package on the production server.
      I think you can download it from
      http://www.microsoft.com/download/en/details.aspx?id=27231

      Alternatively, if you leave your email address can can sent it to you, or upload to my drop box.
      ( I can delete you comment afterwards )

      best regards,
      Nathan

      Delete
  13. Hi Nathan,

    I am one of the early posters on msConnect and took the "flattening" workaround in the reportviewer nested object debacle last year. Hearing that SP1 may have fixed the reportviewer's nested object issues, I am trying to get rid of the flattened shim classes I developed as a workaround for printing shallowly-nested objects through the reportviewer. Unfortunately, it still is not working for me. What I did was:

    Applied the SP1 update to Visual Studio 2010
    Downloaded and installed Reportviewer 2010 SP1
    Made sure my object classes (VB) are prefixed by the directive
    Used the following reportviewer reference syntax:

    =fields! .value.

    All of the 1st level parent object data is printed, but for the child data I get a red x for image fields and #Error for the string captions.

    Any ideas? Thanks -BGood

    ReplyDelete
  14. Note: Some special characters were stripped from my posting. The serializable directive had .GT. and .LT. signs, and the reportviewer syntax was =fields!parentName.value.childName. -Sorry

    ReplyDelete
    Replies
    1. Hi BGood,

      Sounds like you have everything installed that you need.

      The problem may therefore be the code for the classes or database permissions issues.

      Things to check.

      1) Classes are serializable:- I had an issue once where #Error was being thrown for properties on the main objects of the report. I managed to find the problem in the end by passing the object into a 'System.Web.Script.Serialization.JavaScriptSerializer' in the System.Web.Extensions assembly. The properties of the object were causing a stack overflow exception because each class had a property of the same type. - in short, try and serialize it with that serializer and if that doesnt throw any errors you can rule that out

      2) Are you lazy loading the properties - eg loading the data in the getter of the property. I also had this issue as data was not loaded from the DB until the property was requested. When report viewer trys to access the property it was then making a request to the database as the user account the application pool is running as, not the user account my web application was impersonating. This can be sorted out in 2 ways. Firstly, my connection string was using Integrated security to connect to SQL so when the report viewer requested any additional data it needed it didnt do it as an account with access to SQL. On the report it showed most of the fields but not the nested objects. Changing the connection string to specify a username and password would sort this. This does depend a little on your data layer. Option 2 would be to change the identity of the application pool. This is what I do now as you can still use integrated security in the connecton string, report viewer just uses the user account on the app pool. One more option that may also work is to preload the properties of the object if you have implemented caching for the properties read.

      3) depending on your objects that syntax you posted may not be correct. from my example in the post..

      =Fields!Supplier.Value.SupplierLocation.Address1

      in your example this would translate to

      =fields!parentName.value.childName.??????

      do you need

      =fields!parentName.value.childName.childproperty

      where childname is a class, and child property is the property of that class you want to show.

      I think thats about it, generally when i have issues like that now its to do with impersonation and reportviewer not being able to access the database but I have been through all of the above before!

      Nathan

      Delete
  15. Thanks a lot Nathan. I posted at the original msConnect bug thread as well about possible confilct with the serializable() directive. The first few lines of my designer classes look like this:

    _
    Partial Public Class PropImage

    and I wonder if the datacontract serialization directive is interfering with the Serializable() directive?

    Thanks for the suggestions. -BGood

    ReplyDelete
  16. Nathan, I'm sorry for messing up your nicely formatted blog, but my VB syntax is not getting through.

    ReplyDelete
    Replies
    1. Hi no problem,

      Im not sure if it will be easy to show VB on here, there is a C# javascript formatting plugin that may be messing with it.

      Did the object get serialized ok by the javascript serializer?

      are the properties reading more info from the DB when accessed?

      Delete
    2. Nathan,

      Serialization: I can serialize the parent and child object to file just fine with binary serialization.

      Lazy loading: The dataset passed into the reportviewer is the result of a linq query which has been executed toList. I can view the list contents in the debugger and the data and hierarchy is correct. In VB it is passed to the reportviewer as follows:

      Dim rptDataSource = New Microsoft.Reporting.WinForms.ReportDataSource(DatasetName, rentcompBindingSource)
      ReportViewer1.LocalReport.DataSources.Add(rptDataSource)


      My suspicion is that in the reportviewer designer, the datasource is defined as a dataset, not an object. I get the 1st level properties just fine. The 2nd level child values is what is lost.

      Is there a special way to define an object datasource for the designer? It seems like ther was a way to do this in the past. Now the designer is looking for a flat dataset.

      Thanks -BGood

      Delete
    3. The datasource for my report is a simple generic list of classes for example. I have not bound one to a datatable or linq datasource before. It sounds like I could still be permissions. Did you try changing the user account the application pool for the website is running as?

      I did a sample project for this post a little while back which was working with nested objects. You could see if that is working in your environment?

      https://sites.google.com/site/wraithnath/WraithNath.NestedProperties.Web.zip?attredirects=0&d=1

      Delete
  17. Hi Nathan,

    As background, the reportviewer is operating in Local mode from within a Windows forms application. The dataset being passed to the reportviewer is a strongly-typed list of type SaleComp, where SaleComp is a custom object, Public in scope, and marked Serializable. One of SaleComp's properties is PropImage, a Public custom object marked Serializable. The problem is that the PropImage properties are not recognized in the reportviewer when referenced via its parent SaleComp entity.

    Getting back to your serialization suggestion from yesterday, I had assumed that serialization was OK since my own binary serialization routined were working, but when I tried to serialize using the JSON serializer you suggested, I get a circular reference. This is probably from Linq which creates a "lookback" association from child to parent.

    This is getting much more complicated than I thought. I had hoped that the reportviewer's nesting problems were fixed, but maybe not for me! -BGood

    ReplyDelete
    Replies
    1. Hi,

      It may well be the circular reference that is causing the problem for you.

      if you put [XmlIgnore] and [ScriptIgnore] attributes on the property with the circular reference it will then scrip it when serializing. I think its the ScriptIgnore attribute you need but I know its one of the two.

      This will sort that issue and it make work after that. just adding the attributes is worth a try!

      Nathan

      Delete
  18. Hi Nathan,

    Translating the [XmlIgnore] and [ScriptIgnore] directives into VB, I got around the circular references exception with the following annotations on my "lookback" references:

    Xml.Serialization.XmlIgnore()
    System.Web.Script.Serialization.ScriptIgnore()

    Unfortunately, the reportviewer still references my business objects as flat datasets and I get #Error whenever referencing a nested object value.

    Assuming it is not a serialization problem, any guesses where to look next? Here is a summary:

    Environment: VS2010 SP1 / Reportviewer: 2010 SP1
    Reportviewer: Local mode
    Targeting: .net 4.0
    Language: VB
    Dataset: Linq to SQL custom object (1:1 association);
    DBML generated with sqlmetal.exe

    Problem: Dataset is treated as a flat table rather than a hierarchial object
    1st order properties render with correct values (value=fields!fieldname.value)
    2nd order proerties render as "#Error" (value=fields!parent.value.childFieldName)

    Dataset: DataSource is a strongly-typed list of custom object type.
    It is serializable and viewable in the debugger before passing to reportviewer.

    Serialization: Using both binary and DataContract in project.
    The following attributes used to prevent circular references:


    AppDomain: One user reports that the report must execute in the AppDomain in order to access nested object fields.
    I have not tried the following, but it is now supposedly deprecated and obsolete:

    {reportObjectViewerObject}.LocalReport.ExecuteReportInCurrentAppDomain
    (System.Reflection.Assembly.GetExecutingAssembly().Evidence);

    Strong naming: One user reports that strongly-named assemblies render #Error for nested objects

    User forum: gotreportviewer.com reports that fields!parent.value.child does not work in VS2010

    Thanks -BGood

    ReplyDelete
    Replies
    1. Hi BGood,

      Ok, well the serialization should be ok now if the circular references are fixed.

      That leaves changing the identity of the application pool to a user with access to the database if that hasnt been tried.

      Its definitely possible to do it, The sample project I put a link to earlier was funnly working with nested properties. That project doesnt use a database and just populates a datasource from code. It might be worth seeing if that project produces the same #error issue. If it doesnt then it would at least show the fix in SP1 is working, and may then point to a data access issue.

      Also, have you got SQL profiler installed? you could run that when trying to run the report and see if it made any queries for the child property etc.

      ok, just downloaded that project i mentioned, ran it, and got the #error issue. I then checked I had reportviewer SP1 installed (im not on my work machine) I had 2008 SP1 installed. Downloaded ReportViewer 2010 SP1 Installed it, restarted visual studio, re-referenced the reportviewer assemblies (Version 10 i think). ran the app again and it was working.

      Delete
    2. Hi Nathan,

      I do not have SQL profiler installed and wonder why it would be necessary since I am rendering a local RDLC report and passing in all the data from my application.

      I am not sure that the most recent Reportviewer is installed. In my project references it says 10.0.0.0 and I thought some other people have cited a higher build #. Are there separate report designer and redistributable updates? What's the best way to tell?

      Thanks, -BGood

      Delete
    3. Hi BGood,

      Even if the report is in local data mode it can look up any extra information it needs from SQL. It depends on whether the property of you base report object looks up info in properties. I have had to preload and cache properties before.

      Version 10.0.0.0 should be the 2010 version, mine didnt work until i removed the references and re-added them.

      While I was looking for the 2010 runtime (which I downloaded at http://www.microsoft.com/download/en/details.aspx?id=6610) I did stumble across reportviewer 2012. would it be an option to try the 2012 version?

      Delete
  19. Nathan,

    I tried removing and re-adding the Reportviewer dll references with the SP1 download from MS. Still get #Error instead of nested values.

    I tried downloading Reportviewer 2012 Beta, but got caught in a catch-22 dependency with installation of SQL 2012 CLR Types whis was not recognized by the Reportviewer 2012 install.

    If you think of anything else, please let me know. I will also post on MSDN and see if any other ideas.

    Thanks -BGood

    ReplyDelete
  20. Nathan, The MSDN reference is

    http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/e7c0683f-ff8a-4a55-b7f7-78575fac54d9

    -BGood

    ReplyDelete
  21. How do I show nested Object within an object?

    I tried doing subreport within List but that didn't work for me. it throw up an error everyttime when I put the sub report within a list control. However if the sub report is outside a list, it is fine.

    Any ideas?

    ReplyDelete
  22. Sorry, I mean How do I show nested *ListObject* within an object?


    Any ideas?

    ReplyDelete
    Replies
    1. Hi,

      You need to use a sub report, what error was it that you got when you tried it last time?

      Delete
    2. Hi WraithNath, would you be able to do a demo of nested list object using the sub reports?

      Class A has a property of <>Class B


      When I tried to put an empty sub report rdlc inside a list , I got some datasource error.

      Delete
    3. I am having the same problem too.. I found a demo of nested sub report, however this is for the older visual studio 2005.
      http://www.gotreportviewer.com/objectdatasources/index.html

      Could you demo a working nested list object in 2010?

      Thanks

      Delete
    4. Hi, I have done a demo project for this post. There is a link further up. Also you can download it from here:

      https://sites.google.com/site/wraithnath/WraithNath.NestedProperties.Web.zip?attredirects=0&d=1

      That is a working project, When I downloaded and ran it on this machine I had the #error problem too. A quick check showed ReportViewer 2010 SP1 was not installed. Installed it, Restarted VS / my computer and after that it worked.

      Delete
    5. Hi Wraith, I have previously looked at your demo.

      I have seen the demo you posted, it only have nested object, but doesn't have nested LIST object.

      DEMO: Order contains Supplier object

      What I wanted : Order contains a LIST of supplier object

      eg >Suppliers

      thanks

      Delete
  23. --> Be sure you add the fake "Value" property after the first property of the model.
    i.e. if you want to access the datasource property Employee.Department.Name, the expression should be: Employee.Value.Department.Name. <-- Note the .Value

    ReplyDelete
  24. Hello WraithNath,

    Thank you for your post. I have wasted 2-3 days already trying to solve this problem. I have followed your suggestions but I am still having trouble. I am using VS2010 SP1 + ReportViewer 2010 SP1 and VB.NET. Here is what I did:

    1. I turned the serialization on by changing the Serialization Mode of the DBML file. Now all the classes have the Global.System.Runtime.Serialization.DataContractAttribute() attribute and all the properties have the Global.System.Runtime.Serialization.DataMemberAttribute(Order:=XXX) attribute.
    2. All the classes have the Public Sub New() constructor.
    3. In the report, I created a new dataset to point to the main class (named Violations). This object has a child object called ViolationType.
    4. In the textbox's expression, I entered =Fields!ViolationType.Value.viol_name

    Unfortunately, I am still getting the #Error thingy. From what I listed here, can you spot what I did wrong?

    Thank you.

    ReplyDelete
    Replies
    1. Hi DanielD,

      It looks at though you have covered everything I would expect.

      A couple of things you could try...

      1) Try passing your datasource into a System.Web.Script.Serialization.JavaScriptSerializer. This will throw up any issues relating to javascript serialization issues. It could be one of your properties is causing a stack overflow if there are any circular dependencies.

      2) There is a sample project I put together in the post. search for 'Sample Web Project' on this page. Try running that and see if you get the same issue. The project definitely works. I downloaded to a new machine to try it, initially I got the #error problem, I then installed report viewer 2010 SP1, restarted my machine and then the problem went away.

      If the sample project works then perhaps it could be related to how the objects are generated from the DBML file. I must admit I have not used a report in conjunction with data generated from the DBML so this is new for me also :)

      Delete
    2. Thank you for your reply WraithNath. You are right, the sample project you provide here is working for me too. As you suggested, this is probably related to Linq and the way the classes are created.

      I can think of a workaround, but there should be a more elegant solution. This is a very common scenario and we should not have to resort to workarounds.

      I guess the quest continues :). If I find a solution, I will come back and post it here. Thanks for your help.

      Delete
  25. Quick note about the Serialization attribute. If you have any base classes in the mix, those need this attribute, too!

    ReplyDelete
  26. Just wanted to say thanks for the post. After exhaustively decorating all classes to ensure they serialised and deserialised via both XmlSerializer and JavaScriptSerializer, I finally got my project working.

    However, in my case at least, I found the following: ONLY the [Serialize] attribute was required on all classes and their base classes in order for the reports to render correctly.

    Specifically, I removed one by one the other items from the checklist in this article (parameterless constructors, 'ignore' attributes for non-serializable properties, recursive property references, and other requirements to make XmlSerializer and JavaScriptSerializer happy) - and the report still renders.

    Hope this helps. The key thing was to ensure that every possible related class had [Serializable] on it.

    (Using ReportViewer 2010 SP1 on ASP.NET 4.5)

    ReplyDelete
    Replies
    1. Hi,

      Thanks for your added detail. I'm sure this will help others as well.

      Glad you got it working :)

      Nathan

      Delete
  27. Thanks a lot, you saved my day.

    ReplyDelete
  28. Is there anyway to troubleshoot deeper as to what is causing the #Error to show up?? I have marked all my classes as Serializeable, everything has a constructor, everything is public, and I still can't process the report. Any advice?

    ReplyDelete
    Replies
    1. Hi Steven,

      You could try passing the object into a 'System.Web.Script.Serialization.JavaScriptSerializer' in the System.Web.Extensions assembly. This may show up and exception if there are any stack overflows in the serialization process. This may help you get a bit further. Failing that, if the report uses a subquery it could be the impersonation context is lost for the queries done on the sup report. you could change the connect string to include a username and password to see if that helps.

      Delete
  29. For nested class, it works after all checklist are verified in development but giving #Error for nested child property in webserver, how can i fix it . please help me out ASAP

    ReplyDelete
  30. Hello, I read part of the thread of these messages and I could solve my problem and wanted to leave my little bit to post solutions.

    I have a parent class with a child class and contains both inherit from a base class that contains a property of type datarow this I put the non serializable [NonSerialized] and this solved my problem.

    I hope someone will help serve

    ReplyDelete
    Replies
    1. Thank you for adding your comments :)

      Delete
  31. Hello,

    After giving it a lot of thinking I can't make this work.

    I'm using an ObservableCollection as the source of my report. I have tried to serialize this source as XML and it worked, it generate it correctly. All classes are serializable (through [Serializable] attribute), there is a default non-parameter constructor but still I'm getting the #Error on the report.

    I'm using Visual Studio 2012, so ReportViewer 2012 and .Net Framework 4.5 as target.

    Some help would be welcome.

    ReplyDelete
  32. After a few more research I have found why it could have been failing for me. I was using MVVMLight framework too and model classes derive from ObservableObject a class not annotated with the [Serializable] attribute.

    Will research why MVVMLight has not that class as serializable and if they can make it serializable.

    ReplyDelete
    Replies
    1. Hi David,

      Thanks for the update. Sorry I have been stacked out the last few days..

      You may be on to something with the Serializable attribute, in the past for things like that I have just created a small class for the data on the report, then called this from a repository. Its a bit more work but populating other objects from your observable collection may be a way to get it working.

      Nath

      Delete
  33. Hi Nathan
    Like many others I am facing the same problem with the nested objects showing #Error. I have checked all the items from your checklist and seems to be fine. I am using VS 2010 and installed the service pack 1. I was able to run your demo project successfully. Any suggestion is highly appreciated. I am using it in an MVC application.

    ReplyDelete
    Replies
    1. Hey,

      I dont know much about MVC but I may be able to give you a hand. is it a large project that is easy to run? If you could send it to me I can take a look. Alternatively I could connect to your machine with TeamViewer sometime and take a look with you?

      What time zone are you in? Im GMT and evenings would be best.

      Nath

      Delete
    2. Hi Nath

      Thanks for the quick response.

      This report is driving me crazy. Below are the reasons why.

      I have a WCF function that supplies data to the report.

      1. I used the WCF function to populate the report in an ASP.NET project and it rendered correctly with all the nested objects.

      2. I used the same WCF function to populate the report in an MVC project and it had #Error for the nested objects.

      3. Unlike in ASP.NET, MVC doesn't have a ReportViewer control to render. I thought transferring the control to an ASP.NET page (just transferring the control not redirecting to the page itself) might solve it.

      4. Unfortunately, just transferring the control to call a method within an aspx.cs page didn't work since the init method didn't fire.

      5. So, I declared a reportviewer control on the fly and made it render the report and transferred the byte[] array back to the MVC project. To my surprise that also had the #Error for nested objects.

      6. I even made the ASP.NET project to write a file to the local disk without transferring back to the MVC project. But still it had the #Error for nested object.

      7. Only time it works correctly is when I start and stay in the ASP.NET project and load a Webform.

      Is there any suggestion that you want to make in the above 7 points that I have tried so far? I have been stuck on this for 3 days. My fallback plan is to flatten the object. I am not a fan of it although I know it will work. This is a HUGE object with multiple nested objects and falttening it out is a big task. If anybody has any suggestion, I would really appreciate it.

      Nath, I live in USA and my time zone is EST. I am ready to share share my machine in teamweaver whatever time works for you.

      Thanks a lot.
      Aru

      Delete
    3. Hi Aru,

      If the report is working in one scenario but not another I wonder whether it might be security issues.

      How are you child properties populated, is the object loaded as a whole, or do the properties load when first requested?

      Its now 10:30 here, and I think 5am your time so perhaps we can do something this afternoon?

      Nath

      Delete
    4. Hi Nath

      Sorry for the delayed response. The child properties populate as a whole. shall we catch up tomorrow anytime that works for you or on Sunday? I am available all the time.

      Appreciate your support!

      Thanks
      Aru

      Delete
    5. Hi Nath

      After 1 week of research, there is a breakthrough. You were right in that it was a security issue. I set all the permission for the localreport object and then it started to work fine. All the nested objects render perfectly.

      localReport.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));

      Thanks for the support!
      Aru

      Delete
    6. Hi Aru,

      Thanks for the update, sorry I have not been in touch sooner, its been pretty maniac with my day job!

      I'm glad you hear you have got it sorted, I have spent hours on this kind of problem in the past.

      I hope you comments help others in future :)

      Nath

      Delete
  34. Dude thank you, was looking for an example of this a few days ago, thanks a lot!

    Gustavo Neri - Programmer Company Emdurb (Bauru - Brazil)

    ReplyDelete
  35. Hi
    It looks like this is the ultimate blog post in the whole internet on this problem.

    In my case, I have VS2010 SP1, Winforms, I have checked that the sample project works perfectly both for the supplied ASP.Net project and a WinForms project I added. However, in my project the #Error insists! In my case, my entity classes have been generated with nHydrate (nhydrate.codeplex.com) based on Entity Framework, they are serializable and have parameterless constructors. I also tried the suggestion mentioned earlier in this series of entries to set the ProxyCreationEnabled = false, but it does not work.

    So basically i am stuck for the last 2 days. Any suggestion is very welcome!

    Thanks, regards and best wishes for the coming Holiday from Athens, Greece.

    Alex Prinias

    ReplyDelete
    Replies
    1. Hi Alex,

      Sorry for the delay, I have been on holiday for a few weeks!

      If you have got it working in the sample projects at least then its definitely possible on your machine, I have not used nHydrate before so I cant really comment on that. Are the report viewer assemblies in the sample project the same ones you are referencing? I'm sure you have checked this already.

      One thing you could try is passing in your nHydrate objects to a serializer such as the javascript serializer to ensure you don't get any errors back from that (indicating a problem with serializing the class) I had an issue before where there was a recursive property that caused a stack overflow which gave me the #error issue.

      Best regards,

      Nath

      Delete
    2. Hi Nath,
      Thanks for your answer. It looks like I do have a "recursion" issue, in the sense I have a "Patient_Entity" entity which has a "TherapistInCharge" property of type "Therapist_Entity", and this last one has a list of "Patient_Entity" entities for which the therapist is in charge and so on.

      So, what is the recommended approach for this kind od scenarios? How do we somehow "prune" the tree structure to end the recursion? Do we have to create simpler POCO-type objects in parallel with our entities? Or it would be easier to just "flatten" our entity and add the TherapistInChargeName as a string property of the Patient_Entity?

      Thanks again and best regards,
      Alex

      Delete
    3. Depending on what type of serializer you are using you should be able to add an attribute to the property that causes the recursion to ignore it.

      eg
      [JsonIgnore]
      [XmlIgnore]

      (from memory)
      then you ignore the property when serializing the patient / therapist. probably on the patient if a therapist has many patients.

      hope that makes sense!

      Delete
    4. Hi Nath,
      Yes, it does make sense, however the automatically generated entities from NHydrate have the [XmlIgnore] and [SoapIgnore] already set. And the serializer keeps failing. I suspect the problem is deeper, because the entities inherit from Interfaces, which also inherit from some base Entity object which finally inherit from some Entity framework object... And from what I have gathered from the discussion here is that the ignoring of serializations should be going down to the lowest base objects.

      Anyway, all this is telling me that I will face big problems with Reporting Services... After all these years I don't think they are as mature as Crystal Reports which I am trying to replace, which, by the way, are a pain in the a** but at least they are very powerful and they are a pain I have grown to know! :-)
      I suppose I will have to keep researching.... By the way, are there any good alternatives for reporting that you know?

      All the best,
      Alex

      Delete
  36. Hi and Thanks 1000 times for your Blog !!

    However, I think I face a strange problem : I wasn't able to show my nested value until I copied my whole classes inside my main project (it was inside another project [DLL]). Once all my classes copied locally to my project, it worked! the same namespace/class name! the same code. Then, I add again my reference to my DLL, comment all my "local" classes definition, and the problem come back again.

    Is it possible that we cannot use that method if the classes are defined in another assembly (in another DLL than the main WinForm Project).?

    thanks!

    ReplyDelete
    Replies
    1. O.M.G O.M.G I continued searching, and in my DLL project properties (the project that contains the classes definition), in SIGNING pane, my assembly was signed (sign the assembly was checked). My Winform project was not. for my test, I just "uncheck" the "Sign the Assembly" of my referenced DLL, and now, it work. I tried it a few time, and Now i am sure of that behavior.

      Delete
    2. Hey no problem!

      I wrote another post about report viewer where I was having issues with the reports in a seperate assembly. You have to set the report from within the reporting assembly. Check out the method where it's setting the embedded resource at http://wraithnath.blogspot.co.uk/2011/02/visual-studio-2010-report-viewer-object.html?m=0

      Hope that helps!

      Delete
  37. Serializing, yes, but binary serializing, not XML...

    if this serialization is fine, the object must be displayed.

    Try
    'code de test de serialisation
    Dim fs As New FileStream("c:\bf.xml", FileMode.Create)
    Dim bf As New BinaryFormatter()
    bf.Serialize(fs, clsD)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    End Try

    Be carefull about event and unneeded dependencies (hided with attribute) on public, private, protected, ... member (property are ignored only member are used)

    Gpg

    ReplyDelete
  38. Hi,
    I am trying to implement this in WinForms. Still I am getting #error.
    I have made the classes serializable and added default constructor. Also my classes are in a different assembly. Would it make a difference?

    ReplyDelete