Print Page | Close Window

ANY keyword not working in release

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=3092
Printed Date: 13-May-2026 at 1:58pm


Topic: ANY keyword not working in release
Posted By: scottarlp
Subject: ANY keyword not working in release
Date Posted: 14-Nov-2011 at 4:52am
I've got an interesting problem with DF. I have two tables that I'm querying and get different results just changing the Debug Info for the project. When Debug Info is set to full, it works as I would expect. When set to pdb-only or none, it doesn't work unless I add an extra line.
 
Statement looks something like:
 
var result = manager.Employees.Where(employee => employee.Foreman.Any(foreman => foreman.LocationID == locationID)).ToList();
 
Employee is a list of employees.
Foreman is a list of employees that are foremen.
So I'm trying to get back a list of employees that are foremen.
 
To make this work without full debug info, I have to add a method.
 
var result = manager.Employees.Where(employee => employee.Foreman.Any(foreman => foreman.LocationID == locationID)).Select(employee => employee).ToList();
 
First example returns x records in debug and zero records (no error, just no results) in no debug. Second example works in both. Problem is trying to remember to add what I would think should be a needless method to the query all over the code unless I don't understand what's happening.
 
Can you confirm if this is a bug or am I doing something wrong?
Thanks,
Scott



Replies:
Posted By: kimj
Date Posted: 14-Nov-2011 at 4:22pm
Hi Scott,
 
We haven't seen this problem before.  Which version of DevForce are you using, and is this a client-side query or one executed from within a server-side method?
 
We have seen a problem with Release builds for a model project which contains multiple EDMX files.  With this bug the EntityRelations are not always initialized because a static constructor is missing.  This surfaces as an exception.  You may want to check both client and server debug logs to see if anything unusual is logged. 


Posted By: scottarlp
Date Posted: 15-Nov-2011 at 6:49am
Thanks for the feedback. I'm using 6.1.3.0. I've got so many things in our domain model that I haven't been able to pull enough out to create a simple test project. I did notice during more testing some odd things happening and I think it's related to the cache.
 
If I add a line above my query that simply does something like manager.Foremen.ToList(); to force a read of all records, the code runs correctly. If I change that extra line to manager.Foremen.Count(); it returns the correct count, but then the following query goes back to not returning any data.
 
I also tried spinning up a new manager with the same failed results. I then added .With(QueryStrategy.DataSourceOnly) and it worked.
 
I traced the database for each of my tests and the same query was produced and manually running the query returned the expected results. I set the debug trace file and could see what I expected to see there also. It should be getting the data best I can tell.
 
What I don't understand is just the change of Debug Info alters the execution results. I'll try to create a new solution and see if I can narrow it down to something in the project.


Posted By: scottarlp
Date Posted: 15-Nov-2011 at 7:01am
Sorry, forgot to answer one of your questions. I'm running non-distributed in this instance, so everything client side. I also left out an odd piece of information. If I run within VS with any configuration (none, full or pdb-only), it works correctly. Executing the same build from the bin folder produces the problem when not set to full. I love these kinds of problems...  :)


Posted By: kimj
Date Posted: 15-Nov-2011 at 9:41am
It does sound like caching is more likely the cause than the build configuration.  Is it possible that the DefaultQueryStrategy has been set to CacheOnly or that the QueryInversionMode setting has been changed?  I know this doesn't explain the in-Visual Studio vs. out problem either, but I'd first focus more on code paths in the various cases. 
 
If you're able to create a new solution which reproduces the problem(s), you can either upload here or send to IdeaBladeSupportTrack for case #11226.


Posted By: scottarlp
Date Posted: 16-Nov-2011 at 8:05am
Ok, I think I've got a nice little example of what's happening. I created a small project against NorthwindIB. Oddly, the problem I'm seeing was worse than what I first ran into. In this example, simply adding a line of that doesn't even execute will change the results of a query.
 
To see this in action, set the configuration to release (this will turn off the debug info).
 
If you run in VS, it works correctly.
 
If you run the same build (from release folder), it doesn't work.
 
If you comment out the line where orderID = order.OrderID (even though it never executes), it will work.
 
Tell me I'm going crazy lol - this has been a nightmare narrowing down.
 
Scott
 
  uploads/1120/DFAnyTest.zip - uploads/1120/DFAnyTest.zip


Posted By: kimj
Date Posted: 16-Nov-2011 at 10:42am
Thanks, Scott.  This is very, very weird.  Will keep you updated on what we find.


Posted By: kimj
Date Posted: 18-Nov-2011 at 11:29am
Hi Scott,
 
We've created a patch release, 6.1.3.3, to address the problem you encountered.  You can download the release here - http://www.ideablade.com/DevForceBetaBuild/DF2010_v6133RTW1_setup.exe - .  It will be made generally available next week.  The fix is to the generated model code, so you'll need to re-save your EDMX or re-run the .tt for your model(s).
 
The problem was that the EntityProperties, which are static fields on the PropertyMetadata defined on each entity type, were not always initialized correctly.  In a release build, or when code is optimized, the order of initialization could change in unpredictable ways based on other code in the program.  This is why you saw differences between debug and release builds and when code was added or removed, even if that code wasn't executed.  When debugging a release build within Visual Studio I suspect that VS disables optimization, which would explain why the problem didn't surface then.  When doing a "start without debugging" within VS you will see the problem.
 
Please give the patch release a try, and let us know if you have any problems.
 
 


Posted By: scottarlp
Date Posted: 18-Nov-2011 at 11:37am
Great! Thank you very much. I'll give it a try and let you know if I continue to have a problem.



Print Page | Close Window