New Posts New Posts RSS Feed: Error in model generation (code first)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error in model generation (code first)

 Post Reply Post Reply Page  12>
Author
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Topic: Error in model generation (code first)
    Posted: 26-Sep-2012 at 5:05am
The inner execption is null

The thing is if it was a recomposition issue I should be able to use the model, few second after the error, once the recomposition is done  right ? because if I navigate to another screen which use the same model I will still get the same error, not matter how long I wait before to navigate.
That would means the error is more certainly because of Postsharp.

But, if I reference the same model in the silverlight Application it works so I am confused to what is the real cause.


Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 11:05pm
Walid,
The error message about the missing constructor is missleading here. What's actually going on is that the EntityManager fails to instantiate. I can tell that from the following error:
 
Unable to get metadata for xxx.Commun.Domain.Entities.News. Make sure it is a valid entity type or POCO type with a KeyAttribute
 
What does the inner exception say?
 
I see these errors primarly if PostSharp didn't do it's job, but maybe in this case it has something to do with the xap loading. I did test xap loading, but I don't remember if I tested it with a CF domain model in the dynamic xap. I have to put together a small repro and see If I get any issues.
 
Sorry, you are having these issues. We appreciate you attempting this migration. With a beta product there are bound to be issues.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 5:00pm
I wasn't sure if it was in the XAPLoader too so I did rewrite it without yield return.

Same problem.

I then tried to directly use the AddXapAsync method from cocktail and same problem. Below the code I use.
The ActivateWorkspaceAsync method instantiate the view and navigate to it thru Cocktail Navigator service.

ExecuteAsync() is bind to the click event of a button.

        public async overide Task ExecuteAsync()
        {
            try
            {
               await Composition.AddXapAsync("xxx.Commun.Screens.xap");
               await ActivateWorkspaceAsync("xxx.Commun.Screens.ViewModels.News.NewsWorkspaceViewModel, xxx.Commun.Screens, Version=1.0.0.0");
            }
            catch (Exception e)
            {
               ErrorFns.HandleError(e);
            }
        }

Maybe super marcel will come to the rescue ...


Do you plan to provide new beta builds of devforce regulary thru nuget ?

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 4:50pm
I'm afraid we'll need Marcel's help with this, since I'm not familiar with Cocktail. 
 
We did make composition-related changes in both DevForce and Cocktail in the 2012 beta release, but based on this error I don't know whether the problem is there, or in the XapLoader I see in the sample you sent.  Until DevForce has fired the Recomposed event the newly loaded entity types won't be available, and the lack of metadata for these entities could cause an EntityManager constructor to fail.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 2:04pm
I didn't say the 3 models where dynamically loaded in différents xap and not the Security model.
If I set a reference to those model on the appplication it works.

Looks like there is a recomposition issue. Maybe something is broken on my part with the mix of yield return and Task.

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 1:42pm
I will try the Ignore() once I get the domain working. Actually only the Security model works, the 3 others aren't and all get the same error :

Unable to create an instance of EntityManager: CommunEntities. Required constructor not found. Please add the following constructor: public CommunEntities(IdeaBlade.EntityModel.EntityManagerContext).

Each entityManager owns this constructor I you can see in the model I sent you.
What could cause this error ? everything was working in previous version.

In the Log, the domain assemblies are probed on the server.
Probe Assemblies: xxx.Common.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null :: xxx.Commun.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null :: xxx.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 

I can see the log when it instanciate the security domain :
Metadata file 'xxx.Security.xxxDBSecurity.ibmmx' loaded from assembly 'xxx.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 

but nothing about the xxx.Commun.Domain model I currently try to use.


below the full error message :

La composition a produit une seule erreur de composition. La cause initiale est fournie ci-après. Pour plus d'informations, passez en revue la propriété CompositionException.Errors.

1) Unable to get metadata for xxx.Commun.Domain.Entities.News. Make sure it is a valid entity type or POCO type with a KeyAttribute

Résultat : Unable to initialize EntityManager
Unable to get metadata for xxx.Commun.Domain.Entities.News. Make sure it is a valid entity type or POCO type with a KeyAttribute

Résultat : Une exception a été levée par la cible d'un appel.

Résultat : Unable to create an instance of EntityManager: CommunEntities. Required constructor not found. Please add the following constructor: public CommunEntities(IdeaBlade.EntityModel.EntityManagerContext).

Résultat : Une exception s'est produite lors de la tentative de création d'une instance de type xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork.

Résultat : Impossible d'activer le composant 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork'.
Élément : xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  AssemblyCatalog (Assembly="xxx.Commun.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Résultat : Impossible d'obtenir l'exportation 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork (ContractName="xxx.Commun.Services.UnitsOfWork.ICommunUnitOfWork")' du composant 'xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork'.
Élément : xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork (ContractName="xxx.Commun.Services.UnitsOfWork.ICommunUnitOfWork") -->  xxx.Commun.Services.UnitsOfWork.CommunUnitOfWork -->  AssemblyCatalog (Assembly="xxx.Commun.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
La composition a produit une seule erreur de composition. La cause initiale est fournie ci-après. Pour plus d'informations, passez en revue la propriété CompositionException.Errors.


This migration is really a pain in the ass, I started saturday and I still don't have a running application ;(





Edited by Walid - 25-Sep-2012 at 1:55pm
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 10:21am

That looks like the bug.  I saw that mentioned on StackOverflow too, but we're not interested in modifying the EntityFramework source code, at least not right now.  

I think you can work around the issue by using the Ignore method instead of the NotMapped attribute.  I was able to get the model built when I added the following to TiersConfiguration:

Ignore(p => p.AdressePrincipale);
Ignore(p => p.TelephonePrincipal);

.. also making sure to remove the NotMapped attribute from these properties.

Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 3:31am
Found on codeplex there is a bug about NotMapped and inheritance but regarding the suggested fix I am not able to say if it is related or not.

http://entityframework.codeplex.com/workitem/481?FocusElement=CommentTextBox
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 25-Sep-2012 at 2:18am
sent you a link to download the solution in PM

Thanks
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 2:12pm
I'm not able to reproduce the NotMapped issue, although it could be that my model is too simplistic.
 
One other thing to look at is whether you have an older EntityFramework assembly in the Global Assembly Cache, and also ensure that the EntityFramework.dll is in the bin folder of the application project.
 
If that looks good, would you be willing to send us more of your model code?  I'm specifically interested in whether you have a DbContext defined, the full definitions of "Personne", "Adresse" and "Professionel", and what flavor of inheritance you're using.  The EntityManager, and DbContext if present, would help too.  You can send either to me via a PM, or to IdeaBladeSupport.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 12:22pm
I found out for the null reference exception.

in one entity class I had this delcaration :

[DataMember]
public TypePiece? TypePiece { get; set; }

where TypePiece is an enumeration

The correct sentence is

[DataMember]
public int? TypePiece { get; set; }


Pretty hard to find, specially since this model didn't throw any exception with EF 4.3


Only the [NotMapped] issue is left for now.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 11:22am
Yes I found those post too.
The problem in most of them was that in EF5 & .NET4.5 the NotMappedAttribut is in the namespace System.ComponentModel.DataAnnotations.Schema while it is in System.ComponentModel.DataAnnotations while targetting .NET4

When I made my migration I was aware of those problems around EF5 so I targeted .NET4.5 prior upgrading to EF5.
The NotMapped attribut correctly use the good schema namespace.

The weird part is in my base class I have a NotMapped attribut on the EntityAspect property and this one doesn't cause any trouble.
I checked all the reference in the project (I even did compare with the reference on the Temphire model) and nothing is different.

So right now I am stuck :(

For the null reference exception I am still investigating. It might be another model issue because if I comment all my EntityTypeConfiguration I can compile and generate a .ibmmx (of course this file isn't good as it miss some configuration).

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 11:05am
Regarding the issue with applying the Code First package to your base class assembly - we will need to look at making this cleaner.  For now, removing the .cf file will ensure that the DevForce metadata deploy task doesn't kick off.  Instead of installing the package, though, you can just reference the IdeaBlade.EntityModel.Aop assembly (by browsing to the packages folder holding the assemblies).
 
We haven't seen this NullReferenceException issue, and as you say the error message doesn't help.  Is the model project in which you get this error the one referencing the assembly containing the base class?  You mentioned that you created an empty EntityManager to work around the problem building the assembly holding the base class, so one thing to try would be removing this EM.
 
Regarding the attribute problems you mention in your first post, these are due to EF 5 data annotation changes.   We hadn't seen these issues before now, but some quick googling shows that others are having this issue with using NotMapped when inheritance is involved.  We don't have a workaround to suggest right now, but as soon as we do we'll let you know.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 8:04am
Well it contains the bases class of my entities shared with all my domains.
So I need access to Aop for the ProvideEntityAspect attribut


Any idea what/where I should look for to fix the error I did mention earlier ? 
error : An error occurred during metadata generation and a metadata file could not be created.  Error: La référence d'objet n'est pas définie à une instance d'un objet.
The error message doesn't give me any indication on what to do.

Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 4:04am
Originally posted by Walid

Originally posted by Walid

 
When I try to build I get this error when it was working in the previous with the 6.1.8.

Erreur 1 CodeFirst entities were found in this assembly, but an EntityManager or DbContext was not.  You must define a container for these entities in this assembly. xxx.Common.Domain


This assembly doesn't contains any entitymanager or DBContext because it hosts the base class (all abstract) for all the others domains assemblies.

Is it now mandatory to create a DBContext or entitymanager in any assembly hosting a code first class even if all are abstract  ? 
I created an internal empty entityManager to be able to continue the migration but I feel I shouldn't have to.


Like for the global.asax, the server package created a Devforce.cf file that I didn't notice before.

Removing this file fixed it.

 
The DevForce.cf file gets added by the Code-First package. You shouldn't install the Code-First package to a project that doesn't contain model classes.
Back to Top
Walid View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Nov-2010
Posts: 161
Post Options Post Options   Quote Walid Quote  Post ReplyReply Direct Link To This Post Posted: 24-Sep-2012 at 3:33am
Originally posted by mgood

Walid,
Did you completely uninstall DF 2010? Code-First builds currently do not work with DF 2010 and DF 2012 installed side-by-side.

I am doing the migration on a clean VM under Win8 where I only installed VS2012 and devforce/cocktail thru nuget


Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down