views:

114

answers:

3

I have a WinForm app. I compile it, double-click on it. Predictably, csc.exe kicks in, then goes away, and the application comes up.

I am assuming that at this point the application has been jitted, so no reason for csc.exe to kick in ever again.

I then quit the app and start it again. I see csc.exe kick in again.

What's going on?

+4  A: 

Are you using serialization at all? I believe that will build a temporary assembly in some cases. Anything similar in your app?

Note that the JIT compiler is unrelated to csc, so that shouldn't be anything to do with it.

Jon Skeet
@Downvoter: Care to comment? Why was this such a silly idea?
Jon Skeet
My mistake! Accidental click! Already undone! Sorry!
Timwi
@Timwi: Goodo :)
Jon Skeet
@Jon Skeet. Yes, the app is using Web Services serialization, but #1, I generate the serialization assembly during compilation and #2, if it wasn't there, it would have been built during the first time the app was run.
AngryHacker
@AngryHacker: No, temporary serialization assemblies are generated each run, I believe. I wouldn't be at all surprised if that was the problem.
Jon Skeet
@AngryHacker #2 Is not strictly true, if the generation fails. For instance I worked on an application that always threw an exception when generating the serialization assembly due to improper use of an abstract base class; the exception could only be seen if you run in debug mode and change the exception settings to show on thrown exceptions and not just unhandled exceptions. Not saying it applies here.
Richard Hein
@Richard Hein. Could you expand on the incorrect use of an abstract base class? I am seeing exceptions in the debug mode with exception settings setup as you suggest.
AngryHacker
@AngryHacker Well, if this is the root cause you should be getting an XmlSerializationException. To get more information about why (there are multiple causes - not just the abstract base class issue I mentioned) you should run SGEN from the command line against your assembly. (sgen /a: YourAssembly.dll) The output from that should narrow the problem down a bit. I'm trying to remember the scenario with an abstract base class, specifically ... if I can repro it, I'll post an update.
Richard Hein
@Richard Hein It turns out it's not that - the cause is much more benign ( http://stackoverflow.com/questions/3517470/why-am-i-getting-a-serialization-error/3517537 )
AngryHacker
@AngryHacker Yes, that's the error sorry ... FileNotFoundException (not XmlSerializationException) ... because it can't find the serialization assembly. But the reason why it can't find it, is because of another reason. Something cannot be serialized. Try running SGEN on your assembly to find out what fails to be serialized.
Richard Hein
@AngryHacker Also see http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/9f0c169f-c45e-4898-b2c4-f72c816d4b55/ - in this case SGEN failed because of identically named classes.
Richard Hein
In the link I provided, it fails always. I created a dummy project just with my class and it failed anyway. I think it's by design.
AngryHacker
+2  A: 

If you are using serialization it needs to compile a dynamic assembly in order to create the classes required.

This means that most webservice calls will causes csc.exe to be invoked the first time. After that, the dynamic dll should be cache.

There are calls to a web service. However, it's the same call every time, so I am assuming that the serialization assembly would only have to be created once. Why does it create it the second time (i am assuming that is why csc.exe is being called).
AngryHacker
@AngryHacker Are you manually creating the serialization assemblies? If you aren't (just building the project normally) then serialization assemblies are created at runtime, always. Are you using XmlSerializer with XmlTypeMapping or with XmlType? (to create the serialization)
A: 

If you use XmlSerializer (directly or indirectly, i.e. when calling web services) then inside it generates temp assembly with serializer implementation: creates source file based on reflection information and compiles it with csc.exe. You can pre-generate serializers in development time by SGen.

desco