VS 2008 SP1 deletes my .dbml designer file
- Wednesday, August 13, 2008 2:49 AM
As soon as I save any edits to my Linq-to-SQL .dbml file (either using the designer or editing the XML), Visual Studio silently deletes my designer file.
For example, I edit Foo.dbml and my Foo.designer.cs just disappears - gone. And then of course nothing compiles. A check of the .csproj verifies that the designer file has been removed from my project.
What gives? I have a bunch of tables and stored procedures in this .dbml file. I really do no want to start from scratch... and then just have it happen again anyway!
IT WAS WORKING FINE BEFORE I INSTALLED SP1 !!!
Answers
- Wednesday, August 13, 2008 10:45 PM
All Replies
- Wednesday, August 13, 2008 3:04 AM
And when I click "Run Custom Tool" on my .dbml file, I finally at least get an error message: "The custom tool 'MSLinqToSQLGenerator' failed. Unspecified error"
Not exactly helpful.
- Wednesday, August 13, 2008 3:28 AM
OK, Here are the steps to reproduce...
1. Create a new project
2. Add a new "Linq to SQL Classes"
3. Highlight the .dbml file and press F7 to add a partial class and bring it up in the editor
4. In the partial class, add "using System;" as the first line in the file
5. Save all, right click the DBML, and select "Run Custom Tool"
BOOM!!!!
So, the fix? The fix is to move your "using" statements INSIDE the namespace declaration. Not sure why, but it works!!!!
- Wednesday, August 13, 2008 3:55 AM
I submitted a MS Connect bug :
- Wednesday, August 13, 2008 8:04 PMI get the same error. My designer is gone as well. ***!
- Wednesday, August 13, 2008 10:45 PM
- Wednesday, August 27, 2008 6:37 AMThe namespace fix did NOT work in my case ( a complex project with lots of partial classes on both the DataContext and the generated classes).
What DID work was to put an explicit namespace into the .dbml properties "Context Namespace" and "Entity Namespace".
Open the DBML, click anywhere except on a table and look at the properties for the data context itself.
- Wednesday, August 27, 2008 9:59 AM
The explicit namespaces inside the dbml didn't accept my entries.
Moving the using's inside the namespace worked for me.
Thanks for posting this fix, because this bug has been driving me crazy!
By the way: how did you come up with the fix? It seems so odd!
Thanks again,
Dries
- Wednesday, January 07, 2009 10:30 PMMoving the usings inside the namespace merely causes the data context's .cs file to be opened when you View Code on the .dbml in designer view, and does not actually correct the problem, which is that the .designer.cs file is missing.
WARNING: Make sure you know the original contents of your .dbml file in order to proceed with my fix below (i.e., what tables, stored procedures, etc. you originally placed in it.) I accept no responsibility for lost code!
To correct the problem, copy the contents of your data context's .cs file (in case you have important code you added there; it is normally shown as a subordinate under the .dbml file). Delete the .dbml file (this will remove all its subordinates as well). Make sure you jot down the contents of your Settings.settings file (in case you have anything important there) and delete it as well. Then recreate the .dbml file from scratch using the same method you did the very first time you did it. You'll see that the designer.cs file has been properly auto-generated. Then copy back the contents of your original .cs file into the new file.
That's it.
- Thursday, January 08, 2009 3:41 PM
That's not a fix, that just means I have to recreate the file every time I try to compile. Not really acceptable.
I noticed that my MS connect bug now says "wont fix" because MS has abandoned Linq to SQL. Thanks so much MS! Good luck with entity framework. I'll be using NHibernate.
- Monday, January 12, 2009 2:07 AMHere is a quick workaround: Rename the dbml fuile in the Solution Explorer. This will create a new designer.cs file and all you have to do rename it back to its old name.
- Monday, January 12, 2009 3:12 PM
Wow, MS has re-opened my ticket. MS Connect is actually working as it should!
- Tuesday, January 13, 2009 5:56 AM
I ran into the same problem.
What I was adding was code for the partial method OnCreated. I was going to make an identifier value with a new Guid.
When I was using:Code Snippet
namespaceProject.DataAccessLayer
{
{
{
}
}
}
I would then change the code have a UsingCode Snippet
using System;
namespace WildWingersKidsClub.DataAccessLayer
{
{
{
}
}
}
Now when I go back to the Designer I get the Uspecified Error.
The danger with this BUG is that it can cause the *.designer.cs file to disapear. It also leaves the Project file with the belief the file is built and will not rebuild it. Therefore you have to delete the file *.dbml file, removing it from the project (as built) and start over (adding it as not built).
The fix is as stated put Using statements inside the namespace. The only thing I can think of is that having the Using inside the namespace is a given and was not tested if outside the namespae? StyleCop would have stopped this so I'm wondering if someone could have only tested with the using inside the namespace. If StyleCop would not allow them to write the kind of styled code with Using outside the namespace?Code Snippet
namespaceWildWingersKidsClub.DataAccessLayer
{
using System;
{
{
}
}
}
- Friday, January 16, 2009 10:12 PM
Dear gman,
To overcome this error, I've opened up a blank Notepad document and pasted into it the contents of my remaining .cs file (not the missing designer.cs file which is what we're trying to recover, obviously.) Then I empty out the .cs file (not delete it.) Last, I right-click on the .dbml file and select "Run Custom Tool." This effectively restores the designer.cs file.
You can then replace the contents of the .cs file (not the designer.cs file) by pasting back its contents from Notepad.
This appears to prove that Visual Studio 2008 is having trouble reconciling my custom code in my .cs file to the .designer.cs file it automatically generates, and so it decides to destroy the designer.cs file. It is the absence of the designer.cs file that causes the "Unspecified error" message to pop up when you right-click to View Code on the .dbml file while in Designer view.
Check for changes to method signatures in your custom .cs file or other irreconcilable change that may confuse Visual Studio, such as access modifiers that differ in your code from what is shown in the Designer.
--Jose
- Monday, February 16, 2009 4:17 AMStrange :-o)
Better to use 2008 Team edition where this problem doesn't exist in addition to helps in TDD like integrated FxCop, Coverage analysis etc.
AKS
- Proposed As Answer by AnilKumar111 Monday, February 16, 2009 4:26 AM
-