I am trying to create a unit test that will compile an interface that I created from a service reference. The problem is that when I use ICodeCompiler
to compile the interface, it throws error:
Error: The type or namespace name 'RoleAssignment' could not be found (are you missing a using directive or an assembly reference?)
The RoleAssignment
class comes from the service reference. Is there a way I can add to the ICodeCompiler
as a parameter the service reference?
thank you
this is the method I have
CSharpCodeProvider codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
ICodeCompiler compiler = codeProvider.CreateCompiler();
CompilerParameters parametersForInterface = new CompilerParameters();
parametersForInterface.GenerateInMemory = true;
parametersForInterface.ReferencedAssemblies.Add("System.dll");
parametersForInterface.ReferencedAssemblies.Add("System.Data.Services.Client.dll");
parametersForInterface.ReferencedAssemblies.Add("System.ComponentModel.dll");
parametersForInterface.OutputAssembly = "inMemoryAssembly.dll";
StringBuilder interfaceSC = new StringBuilder();
CompilerResults results = compiler.CompileAssemblyFromFile(parametersForInterface, path+ @"a\IA.cs");
StringWriter sw = new StringWriter();
// If there were errors, raise an exception...
foreach (CompilerError ce in results.Errors)
{
if (ce.IsWarning) continue;
sw.WriteLine("{0}({1},{2}: error {3}: {4}", ce.FileName, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText);
}
// If there were errors, raise an exception...
string errorText = sw.ToString();
errorText is the error mentioned above. I have a service reference added to my unit test, and when I add the IA.cs file to my project I get no errors. IA.cs is an interface that I generated from the service reference reference.cs. I don't know if there is a way to add the service reference to the ICodeCompiler Thank you