Bug with Linq2SQL NerdDinner

Apr 7, 2009 at 5:07 PM
I deciced to follow your methods of using Linq To SQL (Can't wait for my book order to arrive)

In using the same code as nerddinner using a newly generated project I keep getting this error:

Error 1 No defining declaration found for implementing declaration of partial method 'NerdDinner.Models.Validation.NerdDinner.OnValidate(System.Data.Linq.ChangeAction)'

The only difference between the code is I added a folder called Validation and  LinqtoSQLand built the classes:

NerdDinner.dbml is in Models\LinqtoSQL folder and Dinner.cs is in Models\Validation

I can't find the cause of this error as the OnValidate(System.Data.Linq.ChangeAction) located in the .Models\Validation

I decided to organize and learn by example and re-create the NerdDinner from the tutorial as it is stated. How can I fix this LinqtoSQL error?

Thanks


Apr 13, 2009 at 5:34 PM
Edited Apr 13, 2009 at 5:37 PM
Has anyone managed to get this working?

 but still error message is :No defining declaration found for implementing declaration of partial method 'NerDinner.OnValidate(System.Data.Linq.ChangeAction)' 


I worte the exact same code as the NerdDinner in the book sample chapter when I re-create this sample exactly as the source code by creating a new project I get the above error.. it is a copy and paste from the original source and still I get the above
? I open the source code provided and it work fine?

Does this mean that I am missing something with Linq2SQL?

So far there is no way I am going to use Linq2SQL if a special version is required. I hope you will address this bug in your book.

Bottom line is this OnValidate for Linq2SQL won't compile on my VS2008 SP1 with Framework 3.5 SP1

Thanks
David.............
Coordinator
Apr 14, 2009 at 2:37 AM
With respect, if the downloaded version works, and yours doesn't, then you MUST have a typo in your local copy. Have you done a Diff between the two folders with a tool like beyond compare?
Apr 14, 2009 at 12:20 PM
Hi,
Yes I have compared and they match exactly now. I thought it was a bug due to folders naming. Since then I have copied and pasted the exact code into a new MVC Web project and the error pops up and prevents compilation. I have created many projects since and still get the error when trying to use the OnValidate.

Tells me that No defining declaration found for implementing declaration  I check the NerdDinner.designer.cs and the OnValidate is as expected. 

The only difference I can see is the build version of the designer?

NerdDinner Source:

//------------------------------------------------------------------------------

// <auto-generated>

// This code was generated by a tool.

// Runtime Version:2.0.50727.3521

//

// Changes to this file may cause incorrect behavior and will be lost if

// the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------

My generated source:

 

//------------------------------------------------------------------------------

// <auto-generated>

// This code was generated by a tool.

// Runtime Version:2.0.50727.3082

//

// Changes to this file may cause incorrect behavior and will be lost if

// the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------


I am using .3082 where as you are using .3521 I have updated my VS2008 to SP1 and my framework is supposed to be the latest version. looks like this is the cause of the problem?


Thanks
David.................

 

Apr 15, 2009 at 4:00 PM
I just installed Windows Vista and Framework 3.5 with Visual Studio 2008 SP1. I have updated all the required patches and still when I create a new project my Linq2SQL designer is now generating another version?

//------------------------------------------------------------------------------

// <auto-generated>

// This code was generated by a tool.

// Runtime Version:2.0.50727.3074

//

// Changes to this file may cause incorrect behavior and will be lost if

// the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------

 

Seems to be going backwards anyone know how I can get my designer for Linq2SQL to use the version in the source?

I would like to use;  Runtime Version:2.0.50727.3521 this will elimate the error with OnValidate.

This is getting confusing anyway MVC Framework can set the correct version to use?

Thanks

 

 

Apr 15, 2009 at 4:17 PM
Edited Apr 15, 2009 at 5:23 PM
Hi,
I managed to find that the versions of the designer are out of sync. Not sure how to get the designer as the assembley is listed as using:

Version: 3.5.0.0
Path: c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Linq.dll

Runetime version: v2.0.50727

I am totally lost now!



Thanks
David..................
May 4, 2009 at 4:57 PM
Ok since no one has any idea about this, I have since bought the book and typed as it is in the book?

What is wrong with this:

using

 

System;

 

using

 

System.Collections.Generic;

 

using

 

System.Linq;

 

using

 

System.Web;

 

using

 

System.Data.Linq;

 

namespace

 

DWCDiary.Models

 

{

 

public partial class Diaries

 

{

 

public bool IsValid

 

{

 

get { return (GetRuleViolations().Count() == 0); }

 

}

 

public IEnumerable<RuleViolation> GetRuleViolations()

 

{

 

yield break;

 

}

 

partial void OnValidate(ChangeAction action)

 

{

 

if (!IsValid)

 

{

 

throw new ApplicationException("Rule violations prevent saving");

 

}

}

}

 

}




Anyone?

Thanks

May 7, 2009 at 3:50 PM
I've got the same problem :) I was trying to create my own application based on Nerddinner and I saw the same error...2 h passed and I still haven't found a solution :(
May 8, 2009 at 1:53 PM

Hi Galz,

Been a couple of weeks and the silence remains.... not sure why still at a loss for this issue. Basicly it shouldn't be happening... 

 

Maybe it is time to listen to; 

"Hi I'm a Mac and I'm a PC"  :-)

Love to get my hands on the designer Runtime Version:2.0.50727.3521!

What version is created on your side?

 

Thanks

David...............

 


 

May 8, 2009 at 4:43 PM

I have solved that but the problem is that I don't know why... :D after sitting and thinking what is wrong with that I've deleted my project and decided to create it once again from the beginning. I started just like the last time following the tutorial but this time I used online html version, and instead of rewriting it all by myself I was just copying code from the html tutorial. After some time I've reached my last checkpoint and suprisingly there was no error at all :) why ? I still don't know, I was comparing my code before with that in tutorial and there was no progress... Thank God it works now and I can proceed ;>

Coordinator
May 8, 2009 at 6:32 PM

Sorry guys, I've been heads down working on TechEd presentations and haven't had the time to look at this. It's nothing personal.

 

Guys, have you tried downloading what's online here (in the first checkin) and using a tool like BeyondCompare from ScooterSoftware (get the free trial) and doing a compare? There's almost always a mispelling or a missing character.

My first guess as to the .NET Framework difference is that you don't have .NET 3.5 SP1. Try visiting http://www.smallestdotnet.com with IE and tell me what version of the framework you have installed.

May 8, 2009 at 10:00 PM

I had 3.5 SP1 so in my case, I suppose it was a missing char... but still I feel weird about minutes spent on comparing :) anyway thanks

May 9, 2009 at 7:01 PM
Hi, I have the following: YOUR PERSONALIZED RESULTS Looks like you have .NET version 3.5 SP1. That's the VERY latest .NET Framework. You don't need to do anything right now. However, you might make sure your system is setup to get updates from WindowsUpdate automatically. This will make sure your system is up to date with the lastest stuff, including the latest .NET Framework. I also have used WinMerge (http://winmerge.org/) to compare other than the Runtime versions all is the same. Interesting thing is that I can run and build your project with no issues on the same machine? I have also deleted the dbml and re-created it in the source provided and do not have any issues.. once I create a new project using Visual Studio 2008 Developer I run in to the problem. I have tried this on Vista and XP and I re-built my XP development machine from scratch and still get the same issue. Darndest thing I have every seen. This is one of those things I just can't let go. VS2008: Microsoft Visual Studio 2008 Version 9.0.30729.1 SP Microsoft .NET Framework Version 3.5 SP1 Hope this helps David................
May 9, 2009 at 7:24 PM

I'm sure David that misspelling is your problem :) try doing like I did :)

Coordinator
May 11, 2009 at 5:28 AM
Have you tried Googling for that version string? 

2009/5/9 dwelford <notifications@codeplex.com>

From: dwelford

Hi, I have the following: YOUR PERSONALIZED RESULTS Looks like you have .NET version 3.5 SP1. That's the VERY latest .NET Framework. You don't need to do anything right now. However, you might make sure your system is setup to get updates fro m WindowsUpdate automatically. This will make sure your system is up to date with the lastest stuff, including the latest .NET Framework. I also have used WinMerge (http://winmerge.org/) to compare other than the Runtime versions all is the same. Interesting thing is that I can run and build your project with no issues on the same machine? I have also deleted the dbml and re-created it in the source provided and do not have any issues.. once I create a new project using Visual Studio 2008 Developer I run in to the problem. I have tried this on Vista and XP and I re-built my XP development machine from scratch and still get the same issue. Darndest thing I have every seen. This is one of those things I just can't let go. VS2008: Microsoft Visual Studio 2008 Version 9.0.30729.1 SP Microsoft .NET Framework Version 3.5 SP1 Hope this helps David................

Read the full discussion online.

To add a post to this discussion, reply to this email (nerddinner@discussions.codeplex.com)

To start a new discussion for this project, email nerddinner@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Scott Hanselman
http://www.hanselman.com
May 11, 2009 at 10:53 AM

Hi Scott,

The version of VS2008 is the subscription version. I have looked and searched the version for the mscorlib.dll, the impression I am getting is this is 'dll hell' returning. I thought this was resolved?

I have downloaded the full VS2008 service pack 1 and the complete Framework 3.5 SP1 both have completed installation as expected. I am guessing this ( and a guess is all I have) with a bug in the version referenced by VS2008... most weird.

Thanks

David............

 

May 11, 2009 at 5:51 PM

Well just when I thought it couldn't get any more confusing. I decided to install VS2008 on the wife's Vista Home addition and updated all the service packs etc.

Re-Created the application once again from scratch and couldn't find any problems?

So it appears that all is well with the code on a non-developer version of a Windows OS.  So I went out and bought a new machine and walla no problem. I copied the same VS2008 project that does not work on the development PC to my Vista Home installation and the project compiled with no problems??
With that I am going to admit to defeat on this item.

I can say that this issue is not related to the NerdDinner code. 

Hope this helps

David.................

 

   

 

 

Coordinator
May 11, 2009 at 5:59 PM
Wow, crazy. Sorry for the trouble.

--
Scott Hanselman - Tiny phone, tiny email


On May 11, 2009, at 10:51 AM, dwelford <notifications@codeplex.com> wrote:

From: dwelford

Well just when I thought it couldn't get any more confusing. I decided to install VS2008 on the wife's Vista Home addition and updated all the service packs etc.

Re-Created the application once again from scratch and couldn't find any problems?

So it appears that all is well with the code on a non-developer version of a Windows OS. So I went out and bought a new machine and walla no problem. I copied the same VS2008 project that does not work on the development PC to my Vista Home installation and the project compiled with no problems??
With that I am going to admit to defeat on this item.

I can say that this issue is not related to the NerdDinner code.

Hope this helps

David.................

Jun 7, 2009 at 2:55 AM

I had a similar issue before, and for me the problem was that I fogot to set the primary key on the table I was using. Please check to see if you have the same issue.

--Guilherme

Jun 11, 2009 at 8:13 AM

OK!!!

Big thanks to Guizones!

I had the same problem now and this primary key tip saved me. I dunno why, but it turns out that only once you have a primary key thats when the designer adds what it calls Extensibility Methods, which are a set of partial methods (OnValidate is one of them).

 

So what do we know so far:

  • For using OnValidate (and other similar partial methods) we need the designer to add the Extensibility Methods.
  • Extensibility Methods are added only when the corresponding SQL table has a primary key.

I cannot think of a reason, but it seems to be like that...

 

David.

Nov 6, 2009 at 10:41 PM

What if for some reason I am in the same boat as justabuzz but I do have the primary keys in both tables? What is the solution on this? I was following the tutorial step by step and one of the tutorials request is that I setup the primary keys for the two tables, I have the primary keys set up, they are connected and everthing. I still get the error message as we see here. Obviously for me the primary key is not the primary reason for the error. Any suggestions on this regard? Thanks in advance.

Nov 7, 2009 at 7:22 AM

Hi there, my conclusion is to switch to EF.. David.

Nov 7, 2009 at 5:45 PM
That is riddles to me. If possible could you be more specific? I do not understand a single thing about that reply. Thanks in advance.

--
Yours truly,
Fahed Al Daye
Nov 8, 2009 at 11:38 AM

Hi,

Sorry, didn't mean to be too cryptic..

Meant to say I moved on to Entity Framework. That's another project Microsoft works on and it turns out that they are ditching the Linq 2 SQL framework in favour of EF, so assuming you are starting a new project, or if it's an easy process for you to switch to EF it's best to go with what's here to stay and that's EF.

 

Hope that helps!

 

Nov 8, 2009 at 4:40 PM
But in the meantime I need to have this error resolved, I mean the Dinner tutorial is stuck in Linq 2 SQL right now and there is no new tutorial update about Entity Framework. I have to finish this tutorial so I know a little about ASP.NET MVC, so that I can work on this project for a friend of mine. So in the meantime, can someone please help me with the problem I am in. I have the same error:
 
1 No defining declaration found for implementing declaration of partial method for 'Dinner.OnValidate(System.Data.Linq.ChangeAction)'
 
and I cannot continue the tutorial after that. Any help would be greatly appreciate it. The tables have their primary keys.

--
Yours truly,
Fahed Al Daye
Coordinator
Nov 8, 2009 at 7:46 PM
Try diffing your dinner.cs with the one in source control?

--
Scott Hanselman - Tiny phone, tiny email


On Nov 8, 2009, at 12:40 PM, foody <notifications@codeplex.com> wrote:

From: foody

But in the meantime I need to have this error resolved, I mean the Dinner tutorial is stuck in Linq 2 SQL right now and there is no new tutorial update about Entity Framework. I have to finish this tutorial so I know a little about ASP.NET MVC, so that I can work on this project for a friend of mine. So in the meantime, can someone please help me with the problem I am in. I have the same error:
1 No defining declaration found for implementing declaration of partial method for 'Dinner.OnValidate(System.Data.Linq.ChangeAction)'
and I cannot continue the tutorial after that. Any help would be greatly appreciate it. The tables have their primary keys.

--
Yours truly,
Fahed Al Daye
Nov 8, 2009 at 7:58 PM
How do you do that and what do you mean by diffing?

--
Yours truly,
Fahed Al Daye
Coordinator
Nov 8, 2009 at 9:04 PM
Differencing. Comparing two text files with a tool like WinDiff or BeyondCompare.

On Sun, Nov 8, 2009 at 12:58 PM, foody <notifications@codeplex.com> wrote:

From: foody

How do you do that and what do you mean by diffing?


--
Yours truly,
Fahed Al Daye

Read the full discussion online.

To add a post to this discussion, reply to this email (nerddinner@discussions.codeplex.com)

To start a new discussion for this project, email nerddinner@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Scott Hanselman
http://www.hanselman.com
Feb 14, 2010 at 4:54 AM

After much searching, I found a solution that worked for me: make sure the Dinner partial class is in the same name space as the model. It didn't seem to make a difference where I put the file. I first tried the Models folder and then I tried creating an App_Code folder. Forcing the namespace did the trick.

namespace NerdDinner.Models
{

    using System.Collections;
    using System.Data.Linq;
    using System;
    using System.Linq;
    using System.Text.RegularExpressions;
    using System.Collections.Generic;


    public partial class Dinner
    {

// etc.

 

May 14, 2010 at 1:25 AM

I ended up here because I got the same error in exactly the same way as described by dwelford. None of the suggestions above helped, but I soon realised that it was purely an issue with invalid data in the database.

 

I continued to the next step in the walkthrough, adding the try/catch (part of it below) , and immediatley got feedback on invalid data. In my case I had incorrect format on some phone numbers.

//POST: /Dinners/Edit/2 

//etc.

 

[AcceptVerbs(HttpVerbs.Post)]

 

 public ActionResult Edit(int id, FormCollection formvalues)

 

{

 

 

 Dinner dinner = dinnerRepository.GetDinner(id);

 

 try 

 

{

 

 

UpdateModel(dinner); 

 

dinnerRepository.Save();

 

 

 

return RedirectToAction("Details", new { id = dinner.DinnerID });

}

 

 

 catch

 

 

Coordinator
May 14, 2010 at 11:11 PM
foody wrote:
But in the meantime I need to have this error resolved, I mean the Dinner tutorial is stuck in Linq 2 SQL right now and there is no new tutorial update about Entity Framework. 

Just an FYI, we've added EF support to the Trunk version on the Source Control tab, as well as other features. We'll be calling that NerdDinner v2 and releasing a ZIP soon as well as that sample is ASP.NET MVC.

To the other problems, when you hit an issue, do you guys compare what you have with the code online using a tool like BeyondCompare or WinDiff?

Aug 10, 2010 at 6:35 AM

Just add the following using directive to the partial Dinner.cs.

using System.Data.Linq;

 

 

Dec 16, 2010 at 4:33 PM

And make sure your partial method signature matches that of the extensibility method declaration:

#region Extensibility Method Definitions
...
partial void OnValidate(System.Data.Linq.ChangeAction action);
 
public partial class Order
{
partial void OnValidate(System.Data.Linq.ChangeAction action)
   {...
David