Issue Details (XML | Word | Printable)

Key: NEO-56
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Major Major
Assignee: Erik Doernenburg
Reporter: Thomas Eyde
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Neo

Fail to generate class when column tag is missing certain attributes (Object reference not set to an instance of an object)

Created: 20/Apr/06 02:55 PM   Updated: 24/Apr/06 04:45 PM
Component/s: Tools
Affects Version/s: 1.4.0
Fix Version/s: 1.4.1

Time Tracking:
Not Specified

Environment: Windows XP sp2. Visual Studio 2003.

Testcase included: yes


 Description  « Hide
When saving the schema xml or running "Run Custom Tool" you get a message box stating "Object reference not set to an instance of an object".

The generated support file contains:
/* NeoCodeGen caught an exception while generating the source code: Object reference not set to an instance of an object.

at Neo.MetaModel.Reader.NorqueReader.ReadAttribute(Entity entity, XmlElement el)
at Neo.MetaModel.Reader.NorqueReader.ReadEntity(Model model, XmlElement el)
at Neo.MetaModel.Reader.NorqueReader.ReadModel(XmlElement el)
at Neo.MetaModel.Reader.NorqueReader.LoadModel(XmlTextReader xmlReader)
at Neo.MetaModel.Reader.NorqueReader.LoadModel(String path)
at Neo.Generator.CodeGen.CodeGenerator.GenerateSupportClasses(String inputFile, TextWriter output)
at Neo.VsTool.CodeGenAdaptor.GenerateCode(String path, String contents)
*/

Cause:
The <!DOCUMENT> instruction is missing and the database/table/column tag is missing one of the following attributes: hidden, primaryKey, required.

Problem:
The quick tutorial xml schema does not contain these attributes, so it's not easy to recognize they are currently required.
The norque.dtd is not included in the msi file, so it's not easy to recognize the reference is needed.

Reason:
The NorqueReader.ReadAttribute method contains lines like:
a.IsPkColumn = ValueForAttribute(el, "primaryKey").Equals("true");

which fails when the attribute is non-existing because the NorqueReader.ValueForAttribute returns null:
return ((attr != null) && (attr.Value != "null")) ? attr.Value : null;

Fix:
Change ValueForAttribute to always return non-null values, like String.Empty.
Or, if the dtd is that important, update the msi and the docs.

TestCase (Add the following to NorqueReaderTests):

string schema_withoutDocument = @"<?xml version='1.0' encoding='ISO-8859-1' standalone='no'?>
<database name='pubs' package='pubs4.Model' defaultIdMethod='none'>
<table name='publishers' javaName='Publisher' subPackage='X' description='Publisher Table'>
<column name='pub_id' type='CHAR' size='4' />
</table>
</database>";

[Test] public void NoDocumentSpecification()

{ GetModelReader(schema_withoutDocument); }

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Erik Doernenburg added a comment - 24/Apr/06 04:45 PM
It is expected that the schema files specify a DTD. The DTD in turn specifies default values for these attributes, which means that the reader does not have to deal with null values.

If we droppped the requirement for the DTD to be specified we would have to add a lot of error reporting and substitution logic for default values to the reader. Why do this if the DTD support in .NET does it for us?

Apparently, it is not clear enough that the schema files must specify a DTD. What would be a good place to remind people of this?