Reputation: 2992
I have been creating a plugin model where code will be written on the server and a dll output will be created and downloaded to the client side.
This works well, but as we also want to have debugging support for the code that is generated in server, I tried the following code to download on client.
public OutputResponse GetObject(string fileName, string sourceCode)
{
string[] assemblies = this.GetAssemblies();
string codeLanguage = "cs";
var dllFilePath = Path.Combine(Path.GetTempPath(), fileName + ".dll");
var pdbFilePath = Path.Combine(Path.GetTempPath(), fileName + ".pdb");
//Delete Existing file
if (File.Exists(dllFilePath))
File.Delete(dllFilePath);
if (File.Exists(pdbFilePath))
File.Delete(pdbFilePath);
Dictionary<string, string> compilerInfo = new Dictionary<string, string>();
compilerInfo.Add("CompilerVersion", "v4.0");
CodeDomProvider provider = CodeDomProvider.CreateProvider(codeLanguage, compilerInfo);
var compilerParameter = new CompilerParameters();
compilerParameter.WarningLevel = 3;
compilerParameter.GenerateExecutable = false;
compilerParameter.GenerateInMemory = false;
compilerParameter.IncludeDebugInformation = true;
compilerParameter.CompilerOptions = "/debug:pdbonly";
compilerParameter.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
compilerParameter.TempFiles.KeepFiles = true;
compilerParameter.OutputAssembly = dllFilePath;
foreach (var assembly in assemblies)
compilerParameter.ReferencedAssemblies.Add(assembly);
var results = provider.CompileAssemblyFromSource(compilerParameter, sourceCode);
string sourceFile = string.Empty;
string pdbFile = Path.Combine(Path.GetDirectoryName(results.PathToAssembly), string.Concat(Path.GetFileNameWithoutExtension(results.PathToAssembly), ".pdb"));
foreach(string file in results.TempFiles)
{
var extension = Path.GetExtension(file);
switch(extension)
{
case ".cs":
sourceFile = file;
break;
}
}
var response = new OutputResponse(results.PathToAssembly, pdbFile, sourceFile);
return response;
}
The dll is generated correctly, and I am renaming the pdb and source file to the dll name, and downloaded to the client folder.
Now when a method is called using in the application which plugs in the dll, the Visual Studio cannot attach the debugger. It says "A matching symbol file was not found in this folder".
Can anyone help me on how to solve this problem.
Upvotes: 4
Views: 462