1

Just getting started on NVelocity (v1.1.1) and it seems to be working just fine.

There's just one small thing that annoys me. I've set up VS2010 to break each time an exception is thrown even though it gets handled somewhere, and when running the following code, it always breaks at the call to Evaluate, stating that it "Cannot read from a closed TextReader" (ObjectDisposedException). I do not have the source code for NVelocity, so I cannot debug.

Am I missing a setting somewhere that causes this? Is it just a harmless bug in NVelocity? The result comes out fine, to me it just seems like something's not quite right.

var velocity = new VelocityEngine();
var properties = new ExtendedProperties();
var context = new VelocityContext(fieldValues);
properties.AddProperty("velocimacro.library", string.Empty); // no library
velocity.Init(properties);

using (var writer = new StringWriter())
{
  velocity.Evaluate(context, writer, null, templateContents);
  return writer.ToString();
}

Exception stack trace:

at System.IO.__Error.ReaderClosed() at System.IO.StringReader.Read(Char[] buffer, Int32 index, Int32 count)
at NVelocity.Runtime.Parser.VelocityCharStream.FillBuff() in c:\...\src\NVelocity\Runtime\Parser\VelocityCharStream.cs:line 313

bernhof
  • 6,219
  • 2
  • 45
  • 71
  • Don't quite have an answer to your question, but if you're willing to dive in it seems the [source code is available](http://nvelocity.codeplex.com/). – Jeroen Mar 15 '12 at 13:02
  • Thanks, I've been looking for the source code myself, however the project you're linking to is a fork of the original NVelocity project. I *could* check out the forked version to see if I can find the source of the problem. Do you know if the original source code of version 1.1.1 is available? – bernhof Mar 15 '12 at 13:24
  • @Jeroen : that's not the canon NVelocity repository. The authoritative repository is at https://github.com/castleproject/MonoRail/tree/master/MR2/NVelocity . The one at codeplex is an unmaintained fork. – Mauricio Scheffer Mar 15 '12 at 13:36
  • @MauricioScheffer ahh yes I see now, sorry for the mis-information! – Jeroen Mar 15 '12 at 14:06

1 Answers1

2

This is a first-chance exception. You can see in the source code that this exception is caught right afterwards within NVelocity code.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Thanks for the source link, I'll have a look at the specifics myself! – bernhof Mar 19 '12 at 14:39
  • @Bernhof : bottom line: it's not a real problem. Read about first-chance exceptions and how to disable them in your debugger. – Mauricio Scheffer Mar 19 '12 at 14:49
  • 1
    I know. I'm just curious to see why the exception is thrown. First-chance or not, exceptions should only be thrown in exceptional situations. And my example really doesn't seem that exceptional. – bernhof Mar 19 '12 at 16:09
  • 1
    @Bernhof : NVelocity is quite old and it was ported from Java Velocity, which is even older... so the code sucks in many places :) – Mauricio Scheffer Mar 19 '12 at 16:16