Print Page | Close Window

Query Includes Trigger Relation Link Exception

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1848
Printed Date: 21-Apr-2026 at 10:39am


Topic: Query Includes Trigger Relation Link Exception
Posted By: ksmith
Subject: Query Includes Trigger Relation Link Exception
Date Posted: 26-May-2010 at 2:42pm
The following exception happens on Windows Server 2008 with IIS 7, Enterprise SQL Server 2008. However, using an exact copy of the database on Windows 7 using Visual Studio 2010 built in web server, this exception does not get thrown. The exception is triggered by an .Include() on a query. Queries without includes run perfectly. And again, I copied the database to SQL Express 2008 on my local machine and the error does not happen. I thought maybe the foreign key names in the database did not match the EDM schema. However, the .Include() work just fine locally and do not trigger this exception. The .NET Framework is 4 in both environments. Any ideas on what could cause this or on how to get more details of the error?
 
Caught exception: System.Data.EntityException: Unable to set field/property .... See InnerException for details. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at IdeaBlade.EntityModel.NavigationEntityProperty.get_RelationLink()
   at IdeaBlade.EntityModel.NavigationListEntityProperty`2.GetEntityReference(EntityWrapper wrapper)
   at IdeaBlade.EntityModel.NavigationListEntityProperty`2.GetValueForSerialization(EntityWrapper ew)
   at IdeaBlade.EntityModel.NavigationListEntityProperty`2.GetValue(TInstance instance)
   at lambda_method(Closure , Object )
   at System.Data.Objects.Internal.EntityProxyFactory.<>c__DisplayClass5.<CreateBaseGetter>b__4(Object entity)
   at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.GetNavigationPropertyValue(RelatedEnd relatedEnd)
   --- End of inner exception stack trace ---
   at IdeaBlade.EntityModel.Server.EntityServerQueryInterceptor.HandleException(Exception e, PersistenceFailure failureType)
   at IdeaBlade.EntityModel.Server.EntityServerQueryInterceptor.OnExecuteQuery()
   at IdeaBlade.EntityModel.Server.EntityServerQueryInterceptor.Execute(IEntityQuery entityQuery, SessionBundle sessionBundle, EntityServer entityServer)
   at IdeaBlade.EntityModel.Server.EntityServer.Fetch(SessionBundle sessionBundle, IEntityQuerySurrogate surrogate)
   at SyncInvokeFetch(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</entry>
 
Thanks
Keith



Replies:
Posted By: ting
Date Posted: 26-May-2010 at 8:18pm
Thats's weird.  Can you post the query with the includes?  Is the client app in Silverlight?


Posted By: ksmith
Date Posted: 27-May-2010 at 6:57am

Yes, the client app is Silverlight. Here is the query:

var query = EntityManager.FieldServiceReports

.Where(fsr => fsr.MembershipUserId == _userId && fsr.ReportDate == SelectedReportDate)

.Include(FieldServiceReport.EntityPropertyNames.FieldServiceRecords);

 
I tried changing to include to another navigation property besides FieldServiceRecords and got the same error.
 
Keith


Posted By: ting
Date Posted: 27-May-2010 at 6:47pm
Ok, the code seems pretty normal.
 
This feels like an assembly mismatch error.  Here are a few things to double check:
1)  Confirm the correct files are on the server.  (I'm sure you've done this already...)
2)  Make sure all the projects are targeted at the .NET 4.0 Framework.
3)  Check that DevForce is not installed on the machine, and there are no DevForce assemblies in the GAC or elsewhere except for your deployment directory.
 
If that fails, I'd try another server and see if it works there.
 


Posted By: ting
Date Posted: 28-May-2010 at 3:56pm

Definitely confirm that all the assemblies are deployed into the bin folders and not in the GAC.  We found a similar support case and that turned out to be the problem.



Posted By: ksmith
Date Posted: 02-Jun-2010 at 3:41pm
I built a Windows Server 2008 RC machine. Added the IIS and Web Server Roles and then installed the .Net Framework 4 on the machine. I marked all of the assemblies in my web project as Copy Local including the assemblies for IdeaBlade 6.0.2 and the Entity Framework assemblies and deployed the solution to the application folder on the server (I followed the deployment instructions in the IdeaBlade Deployment guide). Still the same error. Again, everthing works locally on Windows 7 using the same database that the application is using on the server. Have you tried deploying an application that Windows Server 2008 RC that uses a .Include() in a query? Queries that do not use a .Include() are working on this new server.
 
Thank you for your help.
 


Posted By: ting
Date Posted: 02-Jun-2010 at 6:31pm
Thanks for trying that out.  We will try to reproduce this on our end.


Posted By: ting
Date Posted: 03-Jun-2010 at 5:33pm
Two more things:
 
1)  In the global.asax, try adding:
  IdeaBlade.EntityModel.EntityRelation.InitializeEntityRelations(typeof(FieldServiceReport).Assembly);
 
2)  Take a look at the server-side debuglog.xml to see if there are any unusual errors there.
 


Posted By: ksmith
Date Posted: 04-Jun-2010 at 8:24am
I modified a DevForce sample application to display both customers and orders (using the Include() method) and then deployed it to the server and it worked. Therefore, the problem is specific to my application only. From the EDM, I am generating both the DevForce Entity classes and the EF classes although they are in different namespaces. I plan on refactoring my code to use just the DevForce generated classes. I tried step 1 and that did not work. The log file shows an error probing my domain model assembly where the generated classes reside. I haven't been able to get the probing to work when DevForce starts up.
 
At least I know now that the problem is app specific and not related to the deployment environment.
 
Thank you again for all of your help.


Posted By: ting
Date Posted: 04-Jun-2010 at 3:24pm
I believe we have seen asssembly probing issues when both DevForce and raw Entity Framework models are in the same deployment.  We're looking into this.
 
 


Posted By: ksmith
Date Posted: 04-Jun-2010 at 8:02pm
Finally figured it out. I built the sample application in Release mode and experienced the same problem. I then deployed my application after building it in Debug mode and this problem did not occur. The problem happens when the application is built in Release mode on both Windows 7 and Windows Server 2008. You should be able to duplicate it now.


Posted By: ting
Date Posted: 07-Jun-2010 at 2:56pm

Thanks for the additional research.  This will help us nail it down.



Posted By: ksmith
Date Posted: 08-Jun-2010 at 12:01pm
One last thing to look into...
 
I also ran into a problem testing the application over SSL. I noticed in the DevForce log file that the EntityService.svc starts up with an HTTPS URL but the EntityServer starts up over HTTP when the following in used in the Global.asax file:

System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new IdeaBlade.EntityModel.Web.ServiceVirtualPathProvider()); 

The Silverlight (SL) client could not communicate with the EntityServer over SSL.
 
I deployed to Windows Server 2008 RC 2, IIS 7.5, with an SSL cert installed and accessed the SL client over HTTPS.
 
Thanks


Posted By: ting
Date Posted: 09-Jun-2010 at 3:53pm
Ok I think we have a solution for the Release Build problem.  It appears that the static fields on the EntityRelations class do not initialize in a Release Build if there is no static constructor.
 
The workaround is to define a partial class that defines a static constructor:

  public partial class EntityRelations {

    static EntityRelations() { }

  }

 

If you confirm that this also works for you, we will issue a patch for it.

 

 



Posted By: kimj
Date Posted: 09-Jun-2010 at 6:53pm
Just an addendum to Ting's last post - make sure that you also link the file containing the partial class into your Silverlight domain model project, since the change is needed in both the Silverlight application and the BOS.


Posted By: ksmith
Date Posted: 10-Jun-2010 at 7:28am

This works! I had to do what kimj said as well for it to work. Also, I'm now able to run the application in Release mode and over HTTPS. Great work. Thank you.



Posted By: ting
Date Posted: 10-Jun-2010 at 6:25pm
Ok, we've released a DevForce 6.0.3.1 build that fixes this.  Thanks for the help!



Print Page | Close Window