So I have been looking for a way to do this for a while and every time I find something, it leads to a different problem.
Basically, I have a game console. The console runs snippets of C# code. The compiled assembly needs to be a friend of the current assembly so that the console would know about all the types in the current assembly and could manipulate them.
Problem one: Every time you run a console command, a new assembly is generated (I would love to avoid this if anyone knows how) and for it to be a friend assembly it needs to have the same name as the last one. Unfortunately you can't unload the previous assembly so the new one can't overwrite it. This forces me to use AppDomains.
Problem two: If I make each assembly use a separate AppDomain and then unload the last one, it works but I can't manipulate the objects from the current AppDomain because they don't derive from MarshalByRef so when I pass them as parameters to the script it tries to serialize them. I don't like AppDomains.
So I figured the most painless way would be to just generate assemblies in the same AppDomain with different names and somehow set them as friend assemblies at runtime.
I do realize that this might not be possible so any other alternatives a welcome.
EDIT: To make it more clear. Script needs to access the main/parent assemblies internals. Not the other way around. I can't make everything public in the main assembly because I want the code to be reusable.
You can add InternalsVisibleToAttribute to new assembly.