C# "Assembly.LoadFile" & disable "DllImport" in loaded assembly?

1k Views Asked by At

In C#, Is it possible to dynamicaly load a .NET library at runtime with using something like System.Reflection.Assembly.LoadFile & disabling the loaded library from using [DllImport("someCPP.DLL", EntryPoint ="someFunction")] so that you can't call c++ stuff for security reasons??


The reason for this question is i'm thinking about making a generic openSource browser plugin that could run any .NET code & display things like OpenGL or Direct3D or whatever content you want in the browser using .NET. This would need the loaded .NET library to be secure though by disabling "DllImport" & maybe some other things. Is this possible?

1

There are 1 best solutions below

3
On BEST ANSWER

You can use an application domain with restricted security permissions.

Here is a general introduction to application domains:

And here is the specific permission related to executing unmanaged code: