473,326 Members | 2,081 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,326 software developers and data experts.

Command line compile with csc

When I build my winforms exe using the IDE I have a
perfectly functioning exe. If I try to build the same
project using the .Net Framework csc compiler I get a
seemingly valid exe produced (although it's only 44 Kb
instead of 76 Kb).

When I then run the csc-compiled exe I immediately get
a "System.TypeInitializationException".

What am I missing? I'm guessing there may be some batch
file that sets an environment for csc but my installation
of the Framework (v1.1.4322) contains no batch or command
files of any description. I need to get this compiling
in an environment without the full SDK or VS.Net - only
the .Net Framework will be available in the target
environment (should be enough...).

I'd appreciate replies copied to andrew dot warren at
mincom dot com.

Thanks.
Nov 15 '05 #1
11 3189
Andrew Warren <an*******@discussions.microsoft.com> wrote:
When I build my winforms exe using the IDE I have a
perfectly functioning exe. If I try to build the same
project using the .Net Framework csc compiler I get a
seemingly valid exe produced (although it's only 44 Kb
instead of 76 Kb).

When I then run the csc-compiled exe I immediately get
a "System.TypeInitializationException".

What am I missing? I'm guessing there may be some batch
file that sets an environment for csc but my installation
of the Framework (v1.1.4322) contains no batch or command
files of any description. I need to get this compiling
in an environment without the full SDK or VS.Net - only
the .Net Framework will be available in the target
environment (should be enough...).


Do you have a short but complete example which demonstrates the
problem? It sounds very odd to me. Are you referencing any assemblies
other than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2

Do you have a short but complete example which demonstrates theproblem? It sounds very odd to me. Are you referencing any assembliesother than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.


I am using the following "built-ins" across various
classes:

Microsoft.Win32
System
System.Collections
System.ComponentModel
System.Data
System.Diagnostics
System.Drawing
System.IO
System.Runtime.InteropServices
System.Security
System.Security.Permissions
System.Text
System.Text.RegularExpressions
System.Threading
System.Windows.Forms
System.Xml

It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?

Here is the declaration:
----------------------------------------------------------
[DllImport("kernel32.dll",CharSet=CharSet.Auto,
SetLastError=true)]

[return:MarshalAs(UnmanagedType.Bool)]

private static extern bool SetEnvironmentVariable(string
lpName, string lpValue);
----------------------------------------------------------

I compile with the following command line:
csc /out:myapp.exe /win32icon:myicon.ico /target:winexe
*.cs

The .cs files in the current directory include all forms
and classes for the app as well as the AssemblyInfo.cs
created by the IDE.

I can't really give you a complete example that would
also be short! Suffice to say though that apart from that
API call everything else is bog standard - no funny
stuff, just calls to Framework objects. My main form
uses a TreeView control, a DataGrid, and a couple of
buttons - pretty simple. It parses some XML and
populates the TreeView with node objects of my own class
that inherits from TreeNode. Once the tree is built you
can launch command-line sessions based on parameters
supplied by the selected tree node.
Nov 15 '05 #3
Andrew Warren <an*******@discussions.microsoft.com> wrote:
I am using the following "built-ins" across various
classes:
<snip>

Hmm... they all look okay.
It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?
I wouldn't have thought so...
I can't really give you a complete example that would
also be short!


Have you tried? For instance, have you tried writing an app that pretty
much *just* does the unmanaged API call? If that works, you can rule
that out as a reason for the failure.

The other thing you could try is wrapping the Application.Run call in a
try/catch block, and logging more details of the exception to a file.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Andrew : when you compile via the command line, you must include references
yourself.. For example, your application references Microsoft.Win32 ... so
make sure on your "csc" line, you include
"/r:Microsoft.Win32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.

"Andrew Warren" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...

Do you have a short but complete example which

demonstrates the
problem? It sounds very odd to me. Are you referencing

any assemblies
other than the "built-in" ones?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.


I am using the following "built-ins" across various
classes:

Microsoft.Win32
System
System.Collections
System.ComponentModel
System.Data
System.Diagnostics
System.Drawing
System.IO
System.Runtime.InteropServices
System.Security
System.Security.Permissions
System.Text
System.Text.RegularExpressions
System.Threading
System.Windows.Forms
System.Xml

It just occurred to me that one of my classes makes a
call to an unmanaged Windows API that is not available in
the .Net Framework - could this be a factor?

Here is the declaration:
----------------------------------------------------------
[DllImport("kernel32.dll",CharSet=CharSet.Auto,
SetLastError=true)]

[return:MarshalAs(UnmanagedType.Bool)]

private static extern bool SetEnvironmentVariable(string
lpName, string lpValue);
----------------------------------------------------------

I compile with the following command line:
csc /out:myapp.exe /win32icon:myicon.ico /target:winexe
*.cs

The .cs files in the current directory include all forms
and classes for the app as well as the AssemblyInfo.cs
created by the IDE.

I can't really give you a complete example that would
also be short! Suffice to say though that apart from that
API call everything else is bog standard - no funny
stuff, just calls to Framework objects. My main form
uses a TreeView control, a DataGrid, and a couple of
buttons - pretty simple. It parses some XML and
populates the TreeView with node objects of my own class
that inherits from TreeNode. Once the tree is built you
can launch command-line sessions based on parameters
supplied by the selected tree node.

Nov 15 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
Andrew Warren <an*******@discussions.microsoft.com> wrote:
I am using the following "built-ins" across various
classes:


<snip>

Hmm... they all look okay.


I've just looked at them again - they look like namespaces, not
assemblies. What do you have under the References section of your
project?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Philip Rieck <st***@mckraken.com> wrote:
Andrew : when you compile via the command line, you must include references
yourself.. For example, your application references Microsoft.Win32 ... so
make sure on your "csc" line, you include
"/r:Microsoft.Win32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.


Microsoft.Win32 is actually a namespace, not an assembly. The default
response file for csc automatically adds references for all these
assemblies:

Accessibility.dll
Microsoft.Vsa.dll
System.Configuration.Install.dll
System.Data.dll
System.Design.dll
System.DirectoryServices.dll
System.dll
System.Drawing.Design.dll
System.Drawing.dll
System.EnterpriseServices.dll
System.Management.dll
System.Messaging.dll
System.Runtime.Remoting.dll
System.Runtime.Serialization.Formatters.Soap.dll
System.Security.dll
System.ServiceProcess.dll
System.Web.dll
System.Web.Mobile.dll
System.Web.RegularExpressions.dll
System.Web.Services.dll
System.Windows.Forms.Dll
System.XML.dll

Only assemblies not in the above list need to be explicitly referenced.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Sorry - by "whatever that's defined in" -- I should have said "The assembly
that that namespace is defined in"

Since Andrew said that he's trying to do this without installing the SDK,
I'm wondering if he has no default response file, and so will have to
manually add references to all the referenced assemblies when he does a
compile.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Philip Rieck <st***@mckraken.com> wrote:
Andrew : when you compile via the command line, you must include references yourself.. For example, your application references Microsoft.Win32 ... so make sure on your "csc" line, you include
"/r:Microsoft.Win32.dll" or whatever the assembly name is that that's
defined in. Do this for all assemblies you're referencing.


Microsoft.Win32 is actually a namespace, not an assembly. The default
response file for csc automatically adds references for all these
assemblies:

Accessibility.dll
Microsoft.Vsa.dll
System.Configuration.Install.dll
System.Data.dll
System.Design.dll
System.DirectoryServices.dll
System.dll
System.Drawing.Design.dll
System.Drawing.dll
System.EnterpriseServices.dll
System.Management.dll
System.Messaging.dll
System.Runtime.Remoting.dll
System.Runtime.Serialization.Formatters.Soap.dll
System.Security.dll
System.ServiceProcess.dll
System.Web.dll
System.Web.Mobile.dll
System.Web.RegularExpressions.dll
System.Web.Services.dll
System.Windows.Forms.Dll
System.XML.dll

Only assemblies not in the above list need to be explicitly referenced.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #8
Philip Rieck <st***@mckraken.com> wrote:
Sorry - by "whatever that's defined in" -- I should have said "The assembly
that that namespace is defined in"

Since Andrew said that he's trying to do this without installing the SDK,
I'm wondering if he has no default response file, and so will have to
manually add references to all the referenced assemblies when he does a
compile.


I wouldn't think so. Bear in mind that he *is* managing to compile it.
It's *running* it that is causing problems. Missing an assembly
reference would mean a failure to compile, not to run.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
I ended up logging a call with Microsoft to resolve this
and it turns out that the problem lies with attaching
custom icons to the forms... as soon as the icons are
removed it compiles fine with csc!

There is a workaround - the .resx files for the forms can
be compiled to .resource files using resgen.exe and then
compiled with csc. The downside of this is that it does
not meet my requirement of being able to compile the app
using only the .Net Framework - resgen is part of Visual
Studio.

Still, at least I know what the problem is now!

Thanks for your responses and suggestions. I'll let you
know when I hit on the final solution.
Nov 15 '05 #10
A good thought, but the csc.rsp default response file is
actually part of the .Net Framework rather than the SDK -
it's in the same directory as csc.exe.

See my earlier response today for the answer!
Nov 15 '05 #11
Andrew Warren wrote:
I ended up logging a call with Microsoft to resolve this
and it turns out that the problem lies with attaching
custom icons to the forms... as soon as the icons are
removed it compiles fine with csc!

There is a workaround - the .resx files for the forms can
be compiled to .resource files using resgen.exe and then
compiled with csc. The downside of this is that it does
not meet my requirement of being able to compile the app
using only the .Net Framework - resgen is part of Visual
Studio.

Still, at least I know what the problem is now!

Thanks for your responses and suggestions. I'll let you
know when I hit on the final solution.


Just to make things clear - resgen.exe is included in the .NET Framework
SDK, which is available for free as a download from MS.

While it's not included in the .NET Framework Runtime, it is not
necessary to have Visual Studio to use resgen.exe.

--
mikeb
Nov 15 '05 #12

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

Similar topics

1
by: rforman1 | last post by:
I have found many threads with this question asked and ostensibly answered, but none with an example of how exactly to do it. Help! I know that in order to set up the values of command line...
2
by: aladdin | last post by:
I use outside .jpg picture files in a Windows Form project. I try to compile use csc.exe at command line. I use resgen.exe to generate a resource file like: resgen.exe Form1.resx...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
4
by: Brett | last post by:
I have recently purchased Visual C++ . Net compiler and i am trying to compile a project that i had working in Visual C++ 6.0. When I compile, I am receiving the warning: cl : Command line...
6
by: Todd A | last post by:
If I use the following in my code behind page: Public Class _Default Inherits System.Web.UI.Page The page will compile with no errors from the command line compiler (vbc.exe) But, If I...
1
by: Matt Creely | last post by:
I'm using the vbc.exe to compile a .dll automatically for me. I have all my framework references and imports setup correctly. And it will compile just fine, with a few lines of code commented...
5
by: clsmith66 | last post by:
I've been asked to find out if a project is possible, but I'm not having much luck finding the information I need, I hope some one can help. I need to see if I can build a windows service on the...
0
by: chandan agarwal | last post by:
hi I have been given the task of building vc++ programs at the command line using make software. i have installed gnu make-3.81 version. i was able to build and run makefiles for turbo c++. but...
3
by: Tom Baxter | last post by:
I just set up VS 2008 B2 and did a simple command line compile from the VS command prompt. I received this warning: warning CS1668: Invalid search path 'C:\Program Files\Microsoft...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
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...

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.