代码在服务器上发布后没有运行

时间:2015-10-05 06:53:29

标签: c# asp.net-mvc iis

实际上我想在不重启服务器的情况下动态运行类文件 我尝试使用以下代码。

以下代码在localhost上运行正常,但在服务器上发布时不起作用

CompilerParameters CompilerParams = new CompilerParameters();
string outputDirectory = Directory.GetCurrentDirectory();

CompilerParams.GenerateInMemory = true;
CompilerParams.TreatWarningsAsErrors = false;
CompilerParams.GenerateExecutable = false;
CompilerParams.CompilerOptions = "/optimize";

string[] references = { "System.dll", "System.Linq.dll", AppSession.Analytics.ServerMapPath + "/BITool.dll", "System.ComponentModel.DataAnnotations.dll", AppSession.Analytics.ServerMapPath + "/RDotNet.dll", AppSession.Analytics.ServerMapPath + "/DynamicInterop.dll", "System.Core.dll", AppSession.Analytics.ServerMapPath + "/System.Dynamic.dll" };
CompilerParams.ReferencedAssemblies.AddRange(references);

CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults compile = provider.CompileAssemblyFromSource(CompilerParams, code);

if (compile.Errors.HasErrors)
{
    string text = "Compile error: ";
    foreach (CompilerError ce in compile.Errors)
    {
        text += "rn" + ce.ToString();
    }
    throw new Exception(text);
}

//ExpoloreAssembly(compile.CompiledAssembly);
Module module = compile.CompiledAssembly.GetModules()[0];
Type mt = null;
MethodInfo methInfo = null;

if (module != null)
{
    mt = module.GetType("BITool.Concrete.RIntegration");
}

if (mt != null)
{
    methInfo = mt.GetMethod("RConnectFn");
}

if (methInfo != null)
{
    methInfo.Invoke(null, new object[] { });
}

有人能建议我实现这个目标的方法吗?

0 个答案:

没有答案