ASP.NET on-the-fly compilation and db4o
With db4o, you can persist objects form Java and .NET transparently to a database. You can then query for objects based on their class type.
If you use db4o when writing ASP.NET applications in Visual Studio 2005, you may run into problems. Visual Studio encourages you to put all of your “non-page related” classes in an App_Code folder. While your website is running, you can modify and replace the class source files in that folder, and they will be recompiled on the fly as they’re needed by webpages. This is a very cool feature. Here’s an overview of this and some new stuff in ASP.NET 2.0. As an alternative, you could precompile your site instead of having your code compiled as it’s needed when the site is running.
Anyway, back to db4o. Each time the classes in App_Code are recompiled into a new assembly, the assembly is renamed to have a hash in its name (the name is mangled to be unique), so that there isn’t a name collision. When storing and querying, db4o relies on the fully qualified name of your class and its assembly string, e.g.:
Namespace.Class App_Code.junkCharacters Version=0.0.0.0 ...
No big deal, right? Except that in ASP.NET, different “junkCharacters” are put in the assembly string every time you modify one of the files in App_Code. So, if you store a “Person” into the database, modify some other file in App_Code, and then try and query for “Person,” db4o will think that the Person class you’re querying with is different than the one you stored in the database, and the query will not return any hits.
To get around this, you need to have all of the classes you’re going to use with db4o built into an assembly with a stable name. In the full version of Visual Studio, you can just create another project that contains all of your non-page related code, and then reference it from your ASP.NET project.
Your VS solution might look like this:
- Website
*.aspx
*.aspx.cs
reference to ModelCode
- ModelCode (class library)
*.cs
More details can be found in this helpful post on the db4o forums.
No Comments »
No comments yet.
Leave a comment