3 Replies - 2859 Views - Last Post: 26 April 2010 - 08:07 AM Rate Topic: -----

#1 Guest_Uday Roy*


Reputation:

Runtime compilation error CS1026 in c# when we use linq statement

Posted 26 April 2010 - 06:10 AM

We have an application developed on VS2008 [Asp.Net & C#], in this application we provide the facility to the user to write his/her business logic code. For that purposes we maintained a Businesslogic.cs file where user can write his/her code and our application build it as a BusinessLogic.dll file at runtime.

But the problem is when we introducing Linq statement/code into the BusinessLogic.cs file then it generated compilation error [CS1026 ].

Note that, when we build the dll from VS2008 environment then it working fine with the same code which we write into the BusinessLogic.cs & don't generated any compilation error.

For your information, we using the following code as follows:-
private



bool StartDLLCompite(string sNameSpace)         //sNameSpace holds the all BusinessLogic code 

{

 


bool IsOK = CompileSource(sNameSpace, "BusinessLogic\\BusinessLogic.dll"); 

 


return IsOK; 

}


 
private

 

bool CompileSource(string sSource, string sDLLFile) 

{

 


bool IsProcess = false; 

 


string sFinalSource = string.Empty; 

 


string sTempfile = string.Empty; 

 


Exception DLLCreationerror = new Exception(); 

 


try

{

sFinalSource = sSource;

 

string sSourceFile = String2File(sFinalSource); 

sTempfile = sSourceFile;

 


string sErr = string.Empty; 

 


if (System.IO.File.Exists(sDLLFile)) 

{

System.IO.


File.Delete(sDLLFile); 

}

sErr = BuildCustomDLL(sSourceFile, sDLLFile);

}

 


catch (System.Data.SqlClient.SqlException ex) { } 

 


finally { } 

 


return true; 

}

private

 

string BuildCustomDLL(string sSourceFile, string sDLLFile) 

{

 


string cErr = string.Empty; 

 


int i = 0; 

 


//System.CodeDom.Compiler.CompilerError oErr;

Microsoft.CSharp.

CSharpCodeProvider oCodeProvider = new Microsoft.CSharp.CSharpCodeProvider(); 

 


//System.CodeDom.Compiler.ICodeCompiler oCompiler = oCodeProvider.CreateCompiler();

System.CodeDom.Compiler.

CompilerParameters oCompilerParam = new System.CodeDom.Compiler.CompilerParameters(); 

oCompilerParam = GetDefaultNameSpace(oCompilerParam);

oCompilerParam.GenerateExecutable =


false; 

oCompilerParam.OutputAssembly = sDLLFile;

System.CodeDom.Compiler.


CompilerResults oCompilerResult; 

 


//oCompilerResult = oCompiler.CompileAssemblyFromFile(oCompilerParam, sSourceFile);

oCompilerResult = oCodeProvider.CompileAssemblyFromFile(oCompilerParam, sSourceFile);

 

foreach (System.CodeDom.Compiler.CompilerError oErr in oCompilerResult.Errors) 

{

 


if (oErr.IsWarning) 

{

cErr +=


"Warning No. : " + oErr.ErrorNumber + Environment.NewLine; 

cErr +=


"Warning Text : " + oErr.ErrorText + Environment.NewLine; 

}

 


else

{

cErr +=

"Line No. : " + oErr.Line.ToString() + Environment.NewLine; 

cErr +=


"Column No. : " + oErr.Column.ToString() + Environment.NewLine; 

cErr +=


"Error Text : " + oErr.ErrorText + Environment.NewLine; 

cErr +=


"========================================" + Environment.NewLine; 

}

}

 


return cErr; 

}

//We using the following reference

private

 

System.CodeDom.Compiler.CompilerParameters GetDefaultNameSpace(System.CodeDom.Compiler.CompilerParameters oCompilerParam) 

{

oCompilerParam.ReferencedAssemblies.Add(


"System.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Web.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Xml.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Data.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.configuration.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Core.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Data.Linq.dll"); 

 


oCompilerParam.ReferencedAssemblies.Add("G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Web.Extensions.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Xml.Linq.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Data.DataSetExtensions.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\ResourceConfig\\bin\\Debug\\ResourceConfig.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataControl\\bin\\Debug\\DataControl.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataLayer\\bin\\Debug\\DataLayer.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataService\\bin\\Debug\\DataService.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\MultiSelectComboBox\\bin\\Debug\\MultiSelectComboBox.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\Telerik.Web.UI.dll"); 

 

 


return oCompilerParam; 

}





Please help regarding the above matter.

Regards

uday

Is This A Good Question/Topic? 0

Replies To: Runtime compilation error CS1026 in c# when we use linq statement

#2 udayroy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-April 10

Re: Runtime compilation error CS1026 in c# when we use linq statement

Posted 26 April 2010 - 06:20 AM

We have an application developed on VS2008 [Asp.Net & C#], in this application we provide the facility to the user to write his/her business logic code. For that purposes we maintained a Businesslogic.cs file where user can write his/her code and our application build it as a BusinessLogic.dll file at runtime.

But the problem is when we introducing Linq statement/code into the BusinessLogic.cs file then it generated compilation error [CS1026 ].

Note that, when we build the dll from VS2008 environment then it working fine with the same code which we write into the BusinessLogic.cs & don't generated any compilation error.

For your information, we using the following code as follows:-
private


bool StartDLLCompite(string sNameSpace)         //sNameSpace holds the all BusinessLogic code 

{

 


bool IsOK = CompileSource(sNameSpace, "BusinessLogic\\BusinessLogic.dll"); 

 


return IsOK; 

}


 
private

 

bool CompileSource(string sSource, string sDLLFile) 

{

 


bool IsProcess = false; 

 


string sFinalSource = string.Empty; 

 


string sTempfile = string.Empty; 

 


Exception DLLCreationerror = new Exception(); 

 


try

{

sFinalSource = sSource;

 

string sSourceFile = String2File(sFinalSource); 

sTempfile = sSourceFile;

 


string sErr = string.Empty; 

 


if (System.IO.File.Exists(sDLLFile)) 

{

System.IO.


File.Delete(sDLLFile); 

}

sErr = BuildCustomDLL(sSourceFile, sDLLFile);

}

 


catch (System.Data.SqlClient.SqlException ex) { } 

 


finally { } 

 


return true; 

}

private

 

string BuildCustomDLL(string sSourceFile, string sDLLFile) 

{

 


string cErr = string.Empty; 

 


int i = 0; 

 


//System.CodeDom.Compiler.CompilerError oErr;

Microsoft.CSharp.

CSharpCodeProvider oCodeProvider = new Microsoft.CSharp.CSharpCodeProvider(); 

 


//System.CodeDom.Compiler.ICodeCompiler oCompiler = oCodeProvider.CreateCompiler();

System.CodeDom.Compiler.

CompilerParameters oCompilerParam = new System.CodeDom.Compiler.CompilerParameters(); 

oCompilerParam = GetDefaultNameSpace(oCompilerParam);

oCompilerParam.GenerateExecutable =


false; 

oCompilerParam.OutputAssembly = sDLLFile;

System.CodeDom.Compiler.


CompilerResults oCompilerResult; 

 


//oCompilerResult = oCompiler.CompileAssemblyFromFile(oCompilerParam, sSourceFile);

oCompilerResult = oCodeProvider.CompileAssemblyFromFile(oCompilerParam, sSourceFile);

 

foreach (System.CodeDom.Compiler.CompilerError oErr in oCompilerResult.Errors) 

{

 


if (oErr.IsWarning) 

{

cErr +=


"Warning No. : " + oErr.ErrorNumber + Environment.NewLine; 

cErr +=


"Warning Text : " + oErr.ErrorText + Environment.NewLine; 

}

 


else

{

cErr +=

"Line No. : " + oErr.Line.ToString() + Environment.NewLine; 

cErr +=


"Column No. : " + oErr.Column.ToString() + Environment.NewLine; 

cErr +=


"Error Text : " + oErr.ErrorText + Environment.NewLine; 

cErr +=


"========================================" + Environment.NewLine; 

}

}

 


return cErr; 

}

//We using the following reference

private

 

System.CodeDom.Compiler.CompilerParameters GetDefaultNameSpace(System.CodeDom.Compiler.CompilerParameters oCompilerParam) 

{

oCompilerParam.ReferencedAssemblies.Add(


"System.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Web.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Xml.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.Data.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"System.configuration.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Core.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Data.Linq.dll"); 

 


oCompilerParam.ReferencedAssemblies.Add("G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Web.Extensions.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Xml.Linq.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"G:\\Program Files\\Reference Assemblies\\Microsoft\\Framework\\v3.5\\System.Data.DataSetExtensions.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\ResourceConfig\\bin\\Debug\\ResourceConfig.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataControl\\bin\\Debug\\DataControl.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataLayer\\bin\\Debug\\DataLayer.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\DataService\\bin\\Debug\\DataService.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\MyFolder\\MenuGeneration\\MultiSelectComboBox\\bin\\Debug\\MultiSelectComboBox.dll"); 

oCompilerParam.ReferencedAssemblies.Add(


"H:\\Telerik.Web.UI.dll"); 

 

 


return oCompilerParam; 

}





Please help regarding the above matter.

Regards

uday

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Runtime compilation error CS1026 in c# when we use linq statement

Posted 26 April 2010 - 06:29 AM

Hi there and welcome to DIC. Please for the future surround all your code between the '[code]' tag. Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Runtime compilation error CS1026 in c# when we use linq statement

Posted 26 April 2010 - 08:07 AM

Well since you say this is in ASP.NET w/C# I'm moving it to the ASP.NET Forum :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1