我正在用c#/ mono构建一个控制台应用程序。我想做一些剃须刀解析。我使用下面的行来获取剃刀模板的FileInfo对象。
var applicationLayout = new DirectoryInfo ("../../../path/to/the/folder").GetFiles ("Application.cshtml", SearchOption.AllDirectories) [0];
从Xamarin工作室以调试模式运行时运行正常。
但是,从命令行运行exe时,如
$ mono Path/to/project/bin/Debug/MyConsoleApp.exe
它抛出
Unhandled Exception:
System.NotImplementedException: The method or operation is not implemented.
at Reflect.JobProcessing.JobWorker.Start () <0x37e10e0 + 0x00533> in <filename unknown>:0
at Reflect.Web.v2.JobProcessor.MainClass.Main (System.String[] args) <0x6c7ec8 + 0x0018b> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The method or operation is not implemented.
at Reflect.JobProcessing.JobWorker.Start () <0x37e10e0 + 0x00533> in <filename unknown>:0
at Reflect.Web.v2.JobProcessor.MainClass.Main (System.String[] args) <0x6c7ec8 + 0x0018b> in <filename unknown>:0
这不是很具描述性。通过向控制台输出一些标记,我将罪魁祸首缩小到上面的陈述。在该等代码执行正常之前,但一旦该命令被命中,它就会崩溃。
有什么想法吗? : - )
===编辑===
public void Start ()
{
ReportHeading ("Job worker started");
Report ("I am worker " + Guid.ToString());
Report ("I am working on queue(s): " + string.Join(", ", Queues));
while (_work) {
Report ("Polling for jobs at " + DateTime.UtcNow.ToString ());
var jobModel = JobConfig.CurrentStore.PollForJob (Queues);
var startTime = DateTime.UtcNow;
var endTime = DateTime.MinValue;
double timeDiff = 0;
if (jobModel != null) {
ReportHeading("Job " + jobModel.Guid.ToString () + " started at " + startTime.ToString ());
var job = InstantiateJob (jobModel);
MarkJobAsStarted (jobModel, job);
try
{
job.Perform (jobModel.JobArgs);
MarkJobAsCompeleted (jobModel, job);
}
catch(Exception ex)
{
job.Exception = ex;
MarkJobAsFailed (jobModel, job);
ReportHeading ("JOB ERROR!");
Report ("Exception: " + job.Exception.Message);
Report("Inner exception: " + job.Exception.InnerException.Message);
Report ("Continuing...");
}
}
else
{
Report("No jobs available");
}
endTime = DateTime.UtcNow;
timeDiff = (endTime - startTime).TotalSeconds;
if(jobModel != null)
{
Report ("Job completed in " + timeDiff.ToString() + " seconds");
}
if (timeDiff < PollInterval) {
var sleepTime = (int)(PollInterval - timeDiff);
Report ("Sleeping for " + sleepTime + " seconds");
Thread.Sleep (sleepTime * 1000);
}
}
}