重新启动计算机后动态编译C#时出错工作正常

重新启动计算机后动态编译C#时出错工作正常,c#,.net,windows,windows-services,csc,C#,.net,Windows,Windows Services,Csc,我创建了一些方法(这是唯一的测试方法,用于将问题与非常大的系统隔离开来): private void compilehaloworld() { 系统线程线程睡眠((30000)); 如果(!Directory.Exists(_workingDir)) { CreateDirectory(_workingDir); } SetCurrentDirectory(_workingDir); var csc=new CSharpCodeProvider(new Dictionary(){{“compil

我创建了一些方法(这是唯一的测试方法,用于将问题与非常大的系统隔离开来):

private void compilehaloworld()
{
系统线程线程睡眠((30000));
如果(!Directory.Exists(_workingDir))
{
CreateDirectory(_workingDir);
}
SetCurrentDirectory(_workingDir);
var csc=new CSharpCodeProvider(new Dictionary(){{“compilervision”,“v4.0”});
var参数=新的编译器参数(新[]{“mscorlib.dll”,“System.Core.dll”},“foo.exe”,true);
parameters.GenerateExecutable=true;
CompilerResults results=null;
尝试
{
结果=csc.compileasemblyFromSource(参数,
@“使用系统;
班级计划{
公共静态void Main(字符串[]args){
Console.WriteLine(““哈罗世界!””);
}
}");
}
捕获(例外e)
{
INTA=2;
}
results.Errors.Cast().ToList().ForEach(error=>Console.WriteLine(error.ErrorText));
}
这种方法在99%的机器上运行良好,但在其中一台机器上存在一些问题。当服务器运行了几次(几天)后,我想Windows出现了故障。然后,当我从exe应用程序运行CompileAlloworld()时,一切正常,但当我从简单的空服务运行此方法时,在结果结构中调用CompileAssemblyFromSourceinvoke后,集合中没有错误,但csc.exe返回退出代码-1073741502。。。重新启动服务器后,一切正常,但我不能每天重新启动服务器

我试着在SO中找到一些解决方案。我签入任务管理器,没有csc.exe进程挂起,没有Visual Studio工作,没有VBCSCompiler.exe挂起


请帮帮我。

格式化这台机器-如果这对您的某些部件损坏没有帮助。可能是CPU,可能是RAM。@TomaszJuszczak如果Windows首先知道的是“CPU”或“RAM”,而不是用户模式应用程序。一个p码的。OP没有提到任何问题BSOD@Tomasz很抱歉,您想格式化生产服务器?这是不可能的。
-1073741502
是错误代码
STATUS\u DLL\u INIT\u FAILED
。也许这会为您提供足够的信息来开始诊断问题。这些符号常量分散在Windows SDK中的许多文件中。我通常只是去magnumdb.com看看有没有什么有价值的东西。如果将32位值解释为有符号量时为负数,则可以非常安全地假设
HRESULT
NT\u状态
code。
private void CompileHalloWorld()
{
  System.Threading.Thread.Sleep((30000));

  if (!Directory.Exists(_workingDir))
  {
    Directory.CreateDirectory(_workingDir);
  }
  Directory.SetCurrentDirectory(_workingDir);

  var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } });
  var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "foo.exe", true);
  parameters.GenerateExecutable = true;
  CompilerResults results = null;
  try
  {
    results = csc.CompileAssemblyFromSource(parameters,
      @"using System;
        class Program {
          public static void Main(string[] args) {
            Console.WriteLine(""Hallo World!"");
          }
        }");
  }
  catch (Exception e)
  {
    int a = 2;
  }
  results.Errors.Cast<CompilerError>().ToList().ForEach(error => Console.WriteLine(error.ErrorText));
}