473,398 Members | 2,368 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,398 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 16032
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.