473,322 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

CodeDomProvider.CreateCompiler() is obsolete fix

In code below line

ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler();

in .net 2 causes warning

'System.CodeDom.Compiler.CodeDomProvider.CreateCom piler()' is obsolete:
'Callers should not use the ICodeCompiler interface and should instead use
the methods directly on the CodeDomProvider class. Those inheriting from
CodeDomProvider must still implement this interface, and should exclude this
warning or also obsolete this method.'

How to rewrite code so that warning does not appear ?

code is:

ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters loParameters = new CompilerParameters();
loParameters.ReferencedAssemblies.Add("System.Wind ows.Forms.dll");
loParameters.GenerateInMemory = false;
loParameters.OutputAssembly = "myasm.dll";
CompilerResults loCompiled =
loCompiler.CompileAssemblyFromSource(loParameters, lcCode);

Andrus.

Oct 13 '07 #1
5 16022
Andrus wrote:
How to rewrite code so that warning does not appear ?

code is:

ICodeCompiler loCompiler = new CSharpCodeProvider().CreateCompiler();
CompilerParameters loParameters = new CompilerParameters();
loParameters.ReferencedAssemblies.Add("System.Wind ows.Forms.dll");
loParameters.GenerateInMemory = false;
loParameters.OutputAssembly = "myasm.dll";
CompilerResults loCompiled =
loCompiler.CompileAssemblyFromSource(loParameters, lcCode);

Use the following:

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Windows.Forms. dll")
cp.GenerateInMemory = false;
cp.OutputAssembly = "myasm.dll";

CompilerResults result =
provider.CompileAssemblyFromSource(cp, sourceCode);

Orcas beta2 doesnt throw any deprecation warnings
for this snippet ;).

--
Regards,
Łukasz 'Maly' Ostrowski.
http://maly.nemo.pl/

Oct 13 '07 #2
Use the following:
>
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Windows.Forms. dll")
cp.GenerateInMemory = false;
cp.OutputAssembly = "myasm.dll";

CompilerResults result =
provider.CompileAssemblyFromSource(cp, sourceCode);

Orcas beta2 doesnt throw any deprecation warnings
for this snippet ;).
Łukasz,

thank you.

How to create signed assembly using provider ?
I think I must pass snk file as parameter but how ?

Andrus.
Oct 14 '07 #3
Andrus wrote:
How to create signed assembly using provider ?
I think I must pass snk file as parameter but how ?

First, use the sn.exe tool to generate a keyfile:

$ sn -k someKeyFile.snk

Then, in Your code, add the CompilerOptions setting:

CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Windows.Forms. dll")
cp.GenerateInMemory = false;
cp.OutputAssembly = "myasm.dll";

cp.CompilerOptions = "/keyfile:someKeyFile.snk";

And then upon compilation, the compiler will embeed
the strong name key file to the assembly therefore
making it (strongly named/)(gac installable).

--
Regards,
Łukasz 'Maly' Ostrowski.
http://maly.nemo.pl/

Oct 14 '07 #4
First, use the sn.exe tool to generate a keyfile:
>
$ sn -k someKeyFile.snk

Then, in Your code, add the CompilerOptions setting:

CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Windows.Forms. dll")
cp.GenerateInMemory = false;
cp.OutputAssembly = "myasm.dll";

cp.CompilerOptions = "/keyfile:someKeyFile.snk";

And then upon compilation, the compiler will embeed
the strong name key file to the assembly therefore
making it (strongly named/)(gac installable).
Łukasz,

thank you.
I create assemblies at runtime.
I think that cp.CompilerOptions = "/keyfile:someKeyFile.snk";
requires to distribute private key as separate file with my application.

How to embed snk file into application as resource and force compiler to use
it from resource
or generate it at runtime ?

Andrus.
Oct 15 '07 #5
Andrus wrote:
I create assemblies at runtime.
I think that cp.CompilerOptions = "/keyfile:someKeyFile.snk";
requires to distribute private key as separate file with my
application.
Indeed.
How to embed snk file into application as resource and force compiler
to use it from resource
or generate it at runtime ?

Add a new Resource File to the Project, Add the .snk key file to it,
if the Resource File name was "Resource", and the file name was
keyFile.snk, You will get some resource identifier like
Resource.keyFile typed as byte[].

Create a file stream, and write the byte array to it, You'll get
the resource-embeeded key file as a normal disk file, therefore
You'll be able to use it during assembly compilation.

using (FileStream fs = File.Create("keyFile.snk"))
fs.Write(Resource.keyFile, 0, Resource.keyFile.Length);

And then

cp.CompilerOptions = "/keyfile:keyFile.snk"

should work.

--
Pozdrawiam,
Łukasz 'Maly' Ostrowski.
http://maly.nemo.pl/

Oct 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jbeerni | last post by:
In .NET, you can mark methods and accessors as obsolete by using the directive. I've found some interesting behavior with the directive when used in a class which is referenced as a return type...
4
by: BrianProgrammer | last post by:
I have this code below, that works like a champ, but two lines are continually marked as obsolete. See embeded notes. Private Shared Function TransformHTMLString(ByVal XSLT As String, _ ByVal...
2
by: Steve James | last post by:
I am trying to mark an override method in a derived class as obsolete using the ObsoleteAttribute. The compiler, however is not picking up this attribute and is not generating a warning or an...
1
by: Pardhasaradhy | last post by:
Hi, Please see the following error and revert back as early as possible. I am getting this once I request for the asp.net page. Server Error in '/tanishq' Application. Timed out waiting for...
0
by: Marco Viana | last post by:
Hi, I'm developing an ASP.NET application with Visual Studio .NET 2003 in a Win XP Professional, .NET Framework 1.1 and IIS 5.1 computer with all the lattest patches. When testing a page...
1
by: BrianProgrammer | last post by:
I have this code below, that works like a champ, but two lines are continually marked as obsolete. See embeded notes. Private Shared Function TransformHTMLString(ByVal XSLT As String, _ ByVal...
1
by: Andrew Shitov | last post by:
Hello! /language: option of wsdl.exe says that it accepts a fully-qualified name of a class implementing System.CodeDom.Compiler.CodeDomProvider. Although I was able to provide...
4
by: Phill W. | last post by:
If I have a reusbale (GAC-'registered') assembly that contains two, related classes (imagine a DataSet and DataTable; the former contains instances of the latter, the latter has a reference to its...
9
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.