Thursday, November 18, 2010

Linq to Sql Error BC30002

I slammed up against a Yellow Screen of Death (YSOD) earlier today which just made my day.  And by "made my day" I mean that I wanted to scream, bang my head on the desktop, door and any other hard surface, and any other symbol of extreme frustration and angst which you deem appropriate.

Anyways, this YSOD, gave me the singularly helpful error message of:
BC30002: Type 'System.Data.Linq.Mapping.DatabaseAttribute' is not defined
Now, one would think that was helpful information. After all, it tells you exactly what's wrong, and it even tells you on which file it finds this bit of wrongness.

The problem comes in, when one considers that this particular file is a file that is generated by the Visual Studio IDE.  Worse yet, I was not getting any errors in Visual Studio at all.  Visual Studio was busy telling me how happy its little world was, while IIS was throwing up yellow every time I hit F5.

So, of course I turned to my good friend Google.

And found basically nothing. One person had gotten this error, and found out that it was due to conflicting namespaces.  Unfortunately, that wasn't the case here.

Then I did a slightly different Google search and discovered someone on the DNN boards who had gotten the same message, and that message is apparently an issue of the Web.Config not having all the required assemblies listed for it to do its thing with the LINQ classes.

I sat there for a moment, wondering how that could have happened to me. After all, I built the Web Site application from the ground up this morning.  I added the Linq-to-SQL classes via the IDE.  Visual Studio is supposed to take care of this for me, the same way it's done so a dozens of other times since VS2008 and Linq-to-SQL has came out.

Surprise!

Visual Studio hadn't.

Bascally, my Configuration/Compilation/Assemblies keys was missing this XML key:
add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

After that was added I got a working website, and life once more became good...

4 comments:

Anonymous said...

Hi,
I came across this nasty error as well when transferring an application to production. In the end the only way to solve it was to open the production version in Visual Studio, remove the DBML files. Then recreate a blank DBML with the same name, finally I then copied the three DBML files in design back over to production and it worked!

Anonymous said...

Hello,
You mentioned that you were able to get past this error.
"Compiler Error Message: BC30002: Type 'System.Data.Linq.Mapping.DatabaseAttribute' is not defined." with a solution "Bascally, my Configuration/Compilation/Assemblies keys was missing this XML key:"... can you please elaborate exactly how you fixed this...?

Thanx, in advance...
Regards.,

Stephen Wrighton said...

@anon #1 - That should recreate the keys as needed, as described in my pst.

@Anon #2 - Sorry, I just noticed (thanks to your comment) that the relevant key was missing (it was hiding in the html source though). I've updated the code to display the missing key. AS for how to update, go to Configuration-Compilation-Assemblies, and edit the field for the project.

Anonymous said...

This solution (adding the assembly to the web.config) ACTUALLY fixed my problem! Thank you for posting!

Blog Widget by LinkWithin