It's hard to tell without you showing some actual IL rewriting code.
First thing that pops into my mind is that if you use the .net type system when rewriting the IL, you'll get references to the .net runtime type system.
Like, if you import a reference to typeof(int), or a System.Type, or a MethodInfo, then it will use the running one.
To avoid that you can simply use the Cecil type system.
Jb
> --
> --
> mono-cecil
For primitives, Cecil can automatically create references for you, based on the mscorlib you're referencing. So you can use:
myModule.TypeSystem.Void as a TypeReference.
If you need to import a reference to another type, you have to use Cecil to read the module the type is defined is, and call:
var reference = myModule.Import (theDefinition);
To create a reference scoped for myModule that you can use.
> --
> --
> mono-cecil
You need to use your custom silverlight resolver to resolve the silverlight mscorlib and System modules.
From those modules you can get TypeDefinition/FieldDefinition/MethodDefinition.
Then you import references for those in your module.
> --
> --
> mono-cecil