views:

270

answers:

4

Does anybody know how to make a custom BCL work with the stock CLR? How to discover existing the most essential ties between CLR and BCL and reuse them?

Here is what I have so far: http://lightnet.codeplex.com

+4  A: 

Given the comments, it sounds like you want to use the stock CLR with a custom BCL.

I highly doubt that that will work. The CLR and BCL are likely to have quite a few ties with each other - they will make certain implementation expectations, and rely on them, not unreasonably. For example, the CLR may rely on certain internal types which you wouldn't know about.

I would be reasonably surprised if you managed to get the stock CLR to work with your own BCL implementation, although it would probably be significantly simpler to implement a custom BCL to work with the Mono runtime - at least there you can debug what's going on if you run into problems.

Jon Skeet
+1: I will try to resolve the most important ties for a while. I know some guys are able to do that which makes me feel that it is a solvable problem.
Koistya Navin
@Koistya: One problem is that even if you *can* solve it, you may well end up being broken by a hotfix or a new CLR release.
Jon Skeet
Just thinking.. there is a compiler argument /nostdlib Why would Microsoft expose it other than the possibility to write custom BCLs and compile it against native CLR...
Koistya Navin
@Koistya: How about because you're using it against a custom BCL *and* a custom CLR?
Jon Skeet
If you're using it against a custom BCL and a custom CLR then why it restricts you to using 'System' namespace for declaring base types..
Koistya Navin
@Koistya: I have no idea what you mean, I'm afraid. But I still think it highly unlikely that it was meant for what you're proposing.
Jon Skeet
If you would build a custom BCL it will requires you to write base classes by using 'System' namespace. For example if you create Core.Object, Core.Enum instead of System.Object, System.Enum it just won't let you compile the project.
Koistya Navin
@Koistya: Well the language specification *explicitly* talks about System.Object, System.Enum and various other types, so I'm not surprised about that.
Jon Skeet
A: 

Even if you could write your own BCL, how would you get any other code to use it? All such code is built against the actual BCL, and expects the strong names used in the BCL assemblies.

John Saunders
Ideally there won't be any other code. All code will be build around this custom BCL.
Koistya Navin
So, you won't be using any other part of .NET? It depends on the BCL.
John Saunders
I would use other parts of .net for debugging testing purposes only at this moment. In order to do it, I am trying to compile an assembly which uses custom BCL with '/reference:MyBCL=System' flag http://msdn.microsoft.com/en-us/library/yabyz3h4.aspx
Koistya Navin
+1  A: 
  • Check out Script#, a toolchain for compiling C# to Javascript that was written by someone working at Microsoft and is used internally for some of their webapps. The guy does it by making you compile with /nostdlib and reference his minimally reimplemented BCL. After an assembly is produced, a tool reflects through it and turns it into Javascript. He uses the reimplemented BCL to enable accurate debugging and to prevent you from using features of the BCL that don't make sense in a Javascript context. It looks strikingly like your code does now, including the fact that most of the classes are either empty themselves or only have a few empty methods. This is because the implementation of the BCL's classes/methods are in Javascript, instead.

  • This could be a patent minefield. I learned this with the recent Oracle lawsuit: you're only covered under the community promise if you implement the BCL to spec (though, unlike Java, you do not have to implement the CLR alongside of it. Yes, Microsoft's patent exemption is more liberal than Java's). I think this is a fantastic idea that could be useful in many situations; I can imagine myself using this instead of a DSL, or instead of embedding a scripting language, or instead of pedantically worrying about code security in my plugin architecture. But think about it from Microsoft's perspective- if they allowed patent exemptions for non-compliant BCLs, what's to stop somebody from calling their proprietary product a "non-compliant BCL implementation" and reaping the exemptions?

Alex Forster
Good points. Thanks for the input.
Koistya Navin