none
RIA Services - metadata makes visual studio crash

    Question

  • Hi,

    I have two tables: PersonalInfo and CompanyInfo.

    Both these tables have a foreignkey "AdressId" to "AdressId" in the Adress table (since both persons and companies have adresses).

    I can update my datamodel to show this. Next I add the metadata information so that RIA service will recognise the relations. When I build Visual Studio stops working (crashes and restarts) and after that VS will crash every time I try to open the solution. 

    I guess the problem has to do with the codegenerator that can't descide how to navigate from the Adress class to PersonalInfo class and CompanyInfo class at the same time. Is there a way around this?

    thanks,

    Michael

    Tuesday, February 15, 2011 5:30 PM

Answers

  • Hi Jason,

     

    I believe I have found the problem.

    [MetadataTypeAttribute(typeof(PersonalInfo))] 

    should be

    [MetadataTypeAttribute(typeof(PersonalInfoMetadata))] 

    So I clearly did something wrong, but I don't think VS2010 should die :-)

     

    Can you reproduce this?

     

    Thursday, February 17, 2011 2:01 PM

All replies

  • That sounds like a serious bug and definitely should not happen. My initial guess is that somehow the code generator gets into some sort of cycle from the metadata.

    Can you post your metadata here? We might be able to point out how to fix the data (in a plain text editor) so you could resume work in VS.

    Wednesday, February 16, 2011 1:41 AM
  • I have these tables (yes I know I spelled Address wrong :-))

    Profile:                    PersonalInfo:          Adress: 
    ProfileId             |-----PersonalInfoId     |-- AdressId-------|
    PersonalInfoId -------|     AdressId   --------|   <other data>   |
    <other data>                <other data>                          |
    CompanyInfoId --------|                                           |
    <other data>          |                                           |
                          |     CompanyInfo:                          |
                          |-----ComapnyInfoId                         |
                                AdressId   ---------------------------|
                                <other data>

    
    
    namespace MyProject.Web.Models
    {
      using System.ComponentModel.DataAnnotations;
      using System.Data.Objects.DataClasses;
    
      [MetadataTypeAttribute(typeof(ProfileMetadata))]
      public partial class Profile
      {
    
        internal sealed class ProfileMetadata
        {
          // Metadata classes are not meant to be instantiated.
          private ProfileMetadata()
          {
          }
    
          [Include]
          public PersonalInfo PersonalInfo;
    
          [Include]
          public CompanyInfo CompanyInfo;
        }
      }
    
    //SO FAR SO GOOD
    //ADDING THE CODE BELOW BREAKS VS2010
    
      [MetadataTypeAttribute(typeof(PersonalInfo))]
      public partial class PersonalInfo
      {
        internal sealed class PersonalInfoMetadata
        {
          private PersonalInfoMetadata() { }
    
          [Include]
          public Adress Adress;
        }
      }
    
      [MetadataTypeAttribute(typeof(CompanyInfo))]
      public partial class CompanyInfo
      {
        internal sealed class CompanyInfoMetadata
        {
          private CompanyInfoMetadata() { }
    
          [Include]
          public Adress Adress;
        }
      }
    }
    

    When I add the metadata below the comment AND build VS2010 crashes. After this the VS2010 crashes everytime I try to open the solution. Removing the metadata does not help. I hope this is sufficient information.

    Wednesday, February 16, 2011 3:57 PM
  • Your metadata looks correct. Are you using Entity Framework?

    RIA Services will automatically infer [Include] attributes for properties if the entity type is exposed via a query method. Can you try removing the [Include] from the metadata and adding methods like this to your domain service?

    public IQueriable<CompanyInfo> GetCompanyInfos() { return null; // or real data, if it would be helpful.

    Wednesday, February 16, 2011 5:38 PM
  • No, the IncludeAttribute is never inferred. I think you are thinking of the AssociationAttribute.

    Wednesday, February 16, 2011 8:52 PM
  • Yes I am using EF and have implemented the CRUD methods for PersonalInfo, CompanyInfo and Adress.

    I again included the PersonalInfo and CompanyInfo in the metadata without any problems.

    I then added PersonalInfo metadata as shown in the code snippet above, but I excluded the [include] attribute on Adress. I did not add metadata for CompanyInfo (trying to do one step at a time). I then builded and Visual Studio crashed...

     

    @ColinBlair - I saw your comment, but wanted to try it out just to be test if some pecularity with the include attribute was causing the problem.

    Thursday, February 17, 2011 2:17 AM
  • @ColinBlair: what I meant was that if two entities are associated and both entities are exposed to the client via queries, then the [Include] is not needed. Of course, your are right about the [Association] attribute, the EF domain service infers that from the EF metadata.

    @milund: I made a DB following your schema above, and used that to generate a default EDMX file and doamin service, and marked up the metadata as shown, but it works for me. Perhaps you have customized the EDMX in some unusual way?

    In my sample, the generated code on the client was the same regarless of using [Include]. Perhaps you don't even need them? What breaks if they are not included? That might help get us to the solution. Or, you could send me a copy of your project. My email is my username here @ microsoft dot com.

    Thursday, February 17, 2011 12:50 PM
  • @ColinBlair: what I meant was that if two entities are associated and both entities are exposed to the client via queries, then the [Include] is not needed. Of course, your are right about the [Association] attribute, the EF domain service infers that from the EF metadata.

    That isn't correct Jason, there is no connection between query methods and the IncludeAttribute other then both of them can cause an entity to be generated client side.

    Thursday, February 17, 2011 1:48 PM
  • Hi Jason,

     

    I believe I have found the problem.

    [MetadataTypeAttribute(typeof(PersonalInfo))] 

    should be

    [MetadataTypeAttribute(typeof(PersonalInfoMetadata))] 

    So I clearly did something wrong, but I don't think VS2010 should die :-)

     

    Can you reproduce this?

     

    Thursday, February 17, 2011 2:01 PM
  • @ColinBlair: I think we are talking about the same thing: "both [query method and Include] can cause an entity to be generated client side".

    @milund: Hah! You got it. I can crash my VS now too :-). I'll dig into the issue and get a bug filed. Thanks for reporting the issue and finding the repro.

    Thursday, February 17, 2011 2:13 PM
  • Wow, thanks for tracking this down!  I'll file a bug for it.

    Thursday, February 17, 2011 2:14 PM
  • No problem. Glad to help :-)

    Thursday, February 17, 2011 2:36 PM
  • Cleared this post because I missed milund's post.


    Friday, February 18, 2011 1:31 PM
  • I have the same problem.

    However, VS now crashes every time I open the Silverlight project (even though I removed the offending code in the Web project with an editor; and I also cleared the Generated_Code folder).

    What can help me to open my project again?

    Harald M.

    Wednesday, February 23, 2011 3:17 AM
  • I am sorry I can't help you there. I use versioncontrol to avoid situations like this and that is how I could reproduce the problem multiple times (by making the same mistake again and again... Yell)

    Wednesday, February 23, 2011 3:37 AM
  • Well, I could do the repeated crashes without version control's help ;-)

    However, after

    • manually unlinking the Web project from the Silverlight project in the .csproj
    • deleting all of bin, obj, and Clientbin folders in the Web project folder tree
    • opening both projects and adding the link again

    it works again. So "something" is cached "somewhere" somewhat too eagerly ...

    So it goes ...

    Harald M.

    Wednesday, February 23, 2011 4:16 AM
  • I've seen that behavior too. My guess is that the codegen happens for the client happens before the recompiling the server assemblies. You only need to clear out the either the bin or the obj folders before restarting VS, removing the link is not necessary.

    Wednesday, February 23, 2011 11:21 AM
  • Wow this thread saved my life. I was freaking out with this bug, definately a nasty one.

    Tuesday, March 15, 2011 1:13 PM
  • I experienced the exact same problem, vs2010 crashes on metadata:

      [MetadataTypeAttribute(typeof(PersonalInfo))]
     
    public partial class PersonalInfo
     
    {
       
    internal sealed class PersonalInfoMetadata

    my solution:
     [MetadataTypeAttribute(typeof(PersonalInfo.PersonalInfoMetaData))]

    thanx for the solution, but VS2010 should not crash on this

    Friday, July 08, 2011 7:55 AM