views:

36

answers:

1

We've got an EF model that's using POCO generation for its types. We added a stored procedure and created a function import for it. We then generated a Complex Type for the result set and let the T4 template generate the business contract (POCO).

Everything works great in our development, devint, and QA environments. When we deploy to production the application works for a while and then starts throwing this exception:

System.InvalidOperationException: The type parameter 'POCO' in ExecuteFunction is incompatible with the type 'EFComplexType' returned by the function.

If we recycle the application pool the exception goes away for a little while and then comes back, so we recycle the app pool again, and so on...

We have been unable to reproduce the problem in any environment other than production which is making it very hard to determine the root cause.

I doubt anyone has a pat answer to this, but any thoughts as to what it might be, areas we might want to explore, or thoughts on tracking down the root cause would be helpful.

A: 

Firstly there is the immediate checks. Are your procs the same between dev and production?

Are you using the latest version of the POCO T4 Template, I have found a few bugs in it before.

The Dev to Deploy scenario crops up a lot with EF. First thing to check: Dev Environment is SQL 2008, production is SQL 2005. EF really hassles with this. You need to generate your model on the DB version you are using. Start with that.

The fact that recycling the app pool helps, might point to some form of caching or context retention. Check that your objects scope doesn't live on between requests. If you running a singleton pattern somewhere this is a prime suspect.

Are you dynamically loading assemblies at all?

Would it be possible to post the generated function call code from the datacontext?

Slappy
The sproc is the same in all environments. We figured if it wasn't it would fail immediately, but we have triple-checked it just to be sure.
Craig W.
I just double-checked and we are using the current version of the T4 template.All environments are running the same version of SQL Server (2008).We'll take another look and see if we're leaving ObjectContexts laying around.We're not loading assemblies in our code, but when I used Reflector to poke around in the last method to be called (System.Data.Common.Utils.MetadataHelper.GetAndCheckFunctionImportReturnType) I noticed that in its call stack it does workspace.ImplicitLoadAssemblyForType, so we're wondering if it's getting an old assembly.
Craig W.
The generated function call code is:public ObjectResult<Business.Contracts.ActiveCustomFieldReportResult> GetActiveCustomFieldReport(){ return base.ExecuteFunction<Business.Contracts.ActiveCustomFieldReportResult>("GetActiveCustomFieldReport");}
Craig W.
I did some research on this and it pop up every now and again. Sadly with no resolution. The real kicker here is the app pool recycling. I suspect this is incidental. Your generated signature is rock solid. I would recommend reporting this to MS and see what they say. I am dead keen to find out.
Slappy
Yeah, that's about where we're at with it too. The incidents we've found of it usually indicate it happens first time, every time, but in our case it runs for a while before puking. As I said in my comment on the original post, we're going to try splitting our EF models into two assemblies (one for POCO-generate, the other for non) and see if that fixes it. Not being able to repro in anything other than production makes it even more problematic.
Craig W.