ASP.NETMVCアプリケーションでNVelocityを使用するのに問題があります。メールを生成する方法として使用しています。
渡した詳細がすべて正しいことがわかる限り、テンプレートをロードできません。
コードは次のとおりです。
private const string defaultTemplatePath = "Views\\EmailTemplates\\";
..。
velocityEngine = new VelocityEngine();
basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, defaultTemplatePath);
ExtendedProperties properties = new ExtendedProperties();
properties.Add(RuntimeConstants.RESOURCE_LOADER, "file");
properties.Add(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, basePath);
velocityEngine.Init(properties);
basePathは正しいディレクトリです。値が正しいことを確認するために、値をエクスプローラーに貼り付けました。
if (!velocityEngine.TemplateExists(name))
throw new InvalidOperationException(string.Format("Could not find a template named '{0}'", name));
Template result = velocityEngine.GetTemplate(name);
上記の「name」は、上記のbasePathとして定義されたフォルダ内の有効なファイル名です。ただし、TemplateExistsはfalseを返します。その条件付きをコメントアウトし、GetTemplateメソッド呼び出しで失敗させると、スタックトレースは次のようになります。
at NVelocity.Runtime.Resource.ResourceManagerImpl.LoadResource(String resourceName, ResourceType resourceType, String encoding)
at NVelocity.Runtime.Resource.ResourceManagerImpl.GetResource(String resourceName, ResourceType resourceType, String encoding)
at NVelocity.Runtime.RuntimeInstance.GetTemplate(String name, String encoding)
at NVelocity.Runtime.RuntimeInstance.GetTemplate(String name)
at NVelocity.App.VelocityEngine.GetTemplate(String name)
...
私は今少し行き詰まっています。答えはやみくもに明白だと思いますが、今のところわかりません。