This allows you to include a BuildDateAttribute to the metadata (the example this is taken from is for code revisions). I'm not sure, but you may be able to include code to automatically determine the date and time.
Then you can use it as follows:
Then you can obtain the metadata as follows:
MemberInfo info = typeof(TestClass);
object attributes = info.GetCustomAttributes(false);
if (attributes.Length > 0)
Console.WriteLine( attribute.BuildDate );
I've not tried the code myself but it ought to work. If you do give it a go and get it to automatically insert the current time at build then it'd be great to put as an article on CP (in my opinion).
Hope that helps, let me know how it goes.
Paul "If you can keep your head when all around you have lost theirs, then you probably haven't understood the seriousness of the situation."
- David Brent, from "The Office"
MS Messenger: email@example.com
There isn't anything built into the framework to get that information, but there is a formula used to create the build and revision version numbers for the the assembly. Unfortunately this means that in order to make use of this you have to let those be generated, which can be a pain in the ass if you give them a strong name.
I don't remember what the formula is, but if you check the DOTNET list archives around the last week of December 2001 and first week of January 2002 someone mentions it in reference to decoding when the 1.0 framework assemblies were built.
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
James T. Johnson wrote: I don't remember what the formula is, but if you check the DOTNET list archives around the last week of December 2001 and first week of January 2002 someone mentions it in reference to decoding when the 1.0 framework assemblies were built.
How do you manage to remember that type of stuff James? Don't you have anything better to do? Weren't you working on a book with Tom and Nish? What about school?
Seriously man, get a life!
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
Orlanda Ramos wrote: How do proceed, step by step, to produce for our app and executable
that will install the dotNET framework on win98-2k-xp
and afterwards run our program? ..you know, like normal apps should do!
You have to make sure the .NET run-time is installed before the app can run. Usually it means redistributing dotnetfx.exe available from the MS site.
As you probably know, we have the Windows 98 special effect ( ) : you have to install a localized version of the .NET run-time instead. Look here[^] for more details. Those localized packs are available here[^].
You can pass parameters in the cmdline along with dotnetfx.exe to check against an already installed run-time, install silently, ...
Another way to make your life easier is of course to provide the customer a link to MS Windows update, where this service provides the appropriate upgrades according to the OS.
I'm looking for opinions here, so if the subject interests you, please reply. In the following post, runtime compilation is used to mean simple-to-use, on-the-fly access to the compiler, beyond eval statements, extending to the ability to compile full methods, classes, and assemblies.
1) Is runtime compilation worth the overhead (both in actual runtime cost and in time to implement/use)?
2) Is the ability to unload a previously loaded Assembly (possibly automatically, integrated into the garbage collector) important?
3) WARNING, Long Question: I'm building a .NET library (in C#) which gives full, optionally automated, simple, on-the-fly access to the compiler. The actual compiler access is done... However, building the complicated Remoting/AppDomain infrastructure is taking a while. Without this, there is no way to unload a runtime-compiled assembly before the main application ends. Is this final feature desirable and/or necessary for a good runtime compilation library?
It is now months since you posted this message. I hope you read this. Answers: 1) yes 2) not usually 3) no, not necessary. An interpreter you describe is very useful for testing. If that is the main purpose, memory leakage is not so important. Far more important is the user interface -- the command-line, or GUI.
I appreciate your answers to my questions. I had actually conceived of this library as a tool for self-modifying code or code read in from a database and then executed, as opposed to a testing tool (which would seem redundant, as access to this library merely gives access to the .NET compilers, already present when the .NET framework is installed). In such an environment, I believe that memory leakage would be likely to become an issue. I would appreciate if you would possibly re-answer the third question as below, taking this into account.
3) I'm building a .NET library (in C#) which gives full, optionally automated, simple, on-the-fly access to the compiler. The actual compiler access is done... However, building the complicated Remoting/AppDomain infrastructure is taking a while. Without this, there is no way to unload a runtime-compiled assembly before the main application ends. Is this final feature desirable and/or necessary for a good runtime compilation library?
The answer to 3) really depends on the usage of the solution. Your state the scenario, but there are not enough details in that scenario to answer the question. Why put the source in the DB? Why not compile and store the binary at the same time? What will the binaries be used for? Will the process using the binaries be long or short-lived (the most important question)? How often does the source change?
If you just throw away the process then there is no need for an appdomain infrastructure. Even if you build one, you may still see memory growing. I believe even unloading an assembly still may cause memory leakage -- I seem to remember a problem in the vsa newsgroup, anyway. Perhaps it is the string cache (interned strings). If the only sure-fire way is to use a temp process, your solution is simplified -- you only need remoting.
So you can look at the appdomain stuff as an optimization, and it may be you are optimizing something which does not need to be optimized. As I said, there is not enough info in your scenario to say exactly what is important.
For myself, I was thinking of a .net interpreter. Mainly for testing. It is very useful to have an incrementaly constructed environment for testing. Sometimes you don't want to write a whole program to test one function. You want to type something on a command line or use a gui and have the function tested. NUnit etc. are nice, but they are really for automated testing. To test interactively you need an interpreter, that can create typed variables, and can pass the values of those vars to functions, using a commmand line or a gui.
An interpreter, as I envision, would have to be able to do some run-time compiling, at least of expressions and functions. Command-line or gui variable assignments can be done with reflection, but expression evaluation must be very rich, as rich as a .net language, so you need a full-blown compile. If nobody does it I will do it someday. As I said, it is a time saver.
In such an environment memory will be wasted (all the little dlls created each time a change is made to an expression). But it does not really matter.
Thank you for your points... I hadn't even thought of my runtime compilation component as a part of a logic-testing environment, and the features of a testing environment that you point out make the problem of memory leakage mostly irrelevant. Unfortunately, the points that you've made may not hold for my situation. The process (although not the thread) that requires code compilation in my solution should be rather long-lived, as it is a server in a centralized client-server architecture. However, thanks to your arguments, I've realized that an effective way to solve my problem is just to precompile each piece of code at startup of the server, then to access the compiled types. Although this may be expensive in terms of memory, it's much more efficient in terms of programming time required. I intend to polish my design of my existing Runtime Compiler interfaces slightly, then I'll use that. Once the entire server is finished, I'll probably write a CodeProject article on it... As this will be my first significant networking effort, aside from basic tests, the lessons that I learn may be useful to others working on other networking projects.
Just curious about the "expensive in terms of memory" comment. In one of our apps, we are generating code dynamically and compiling it, at either design-time or run-time, according to the user's requirements. Noticing that the codedom compiler was simpler than vsa, and allows C#, we used that. I noticed that compilation occurs out-of-process, except for jscript.net, even if you specify in-memory. If you force the compile into another process (in the case of jscript) the overhead seems to be entirely in time and not memory. Unless I am missing something.
We had to allow run-time code generation because the user's object hierarchy might be built at run-time. Normally, however, the hierarchy is built, code is generated and compiled, all at design-time. If you are curious, the app provides a way to graphically connect objects to realtime data sources, for process control and similar purposes. The compilation is needed for expression evaluation, and to avoid boxing during data transfer.
True, compilation appears to work out-of-process... Except that once compilation is done, the CompilerResults object returned contains an Assembly object. The instant that the Assembly object is loaded into the process's memory (which can happen indirectly by loading the CompilerResults return value), the assembly (with all accompanying code and metainformation) is apparently irrevocably loaded into the process's AppDomain. This consumes memory. If I'm mistaken, please let me know.
I have a client connecting to a server using sockets but when my client goes to send something to the server I don't know what event to use on the server side to see if it is there yet. Could someone help me... Oh and I need it to be asynchronous.
I have my main app running in the default appdomain. I load a plugin manager class in a new AppDomain(plugin). I pass an instance(Connection class) from my main appdomain to the "plugin" appdomain by ObjectHandle. My plugin manager class then loads the plugin assemblies. These assemblies in turn registers to some events from the Connection reference in the "plugin" appdomain. Everything (loading/unloading/events/methods/etc) functions as it should except, when registering the events in my plugin , the plugin's assembly gets loaded in the main appdomain.
The question is how can i "subscribe" to these events without the main appdomian havin to load the plugin assembly? I have thought perhaps "chaining" the events to a new class in the plugin manager assembly and let my plugin subscribe to those. Seems like a lot of work (and the possiblitlity of creating duplicate/error-prone code).
Damn its seems a language is sometimes too type-safe for your liking.
Any input would be appreciated. I can mail you the code as well. A bit much too post.
I think the recommended solution is to create a small assembly containing the portions of code to be shared between te main app and the plugins. In your case it would include the delegate definitions as well as anything else that both sides need to use.
The idea is to keep this assembly small so you don't incur a large penalty for loading it twice.
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
James T. Johnson wrote: I think the recommended solution is to create a small assembly containing the portions of code to be shared between te main app and the plugins. In your case it would include the delegate definitions as well as anything else that both sides need to use.
I ended up makin a "proxy" class for the object that fires these events. Basically:
con.Listener.OnPublic += new PublicMessageEventHandler(OnPublicMessage);
publicvoid OnPublicMessage(UserInfo ui, string channel, string message)
if (Public != null)
Public(ui, channel, message);
//I change the event names to be "inline" with the recommendedpublicevent Sharkbite.Irc.PublicMessageEventHandler Public;
Now this work nicely, but I will be a pain in the $#% for all the events about 50, as I can see no way of get parameters for a delegate via reflection. I think i can add/remove the delegates once I have all my event raising methods in place. Maybe I can do some filtering...but there seems no way I can do the raising method programatically.
The single event I have implementented works as should, and the main appdomain does NOT load the plugin's type. Thus the file is deletable once the appdomain is unloaded and it even allows me to debug, and invoke the plugin.
Another idea I had was perhaps make an abstract base class that already has all the consumer methods in place that will act as a template for the plugin the pass a downcasted instance of the plugin. But again I wasnt sure ifthe main appdomain would load it.
Yet another (but I have now clue on this) is to make my own implement ation of a RealProxy object. Everything seems to point to that...