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);
}
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?