Load dll in domain and CreateInstance

User avatar
TooTallTommyT
Posts: 15
Joined: Tue Aug 21, 2018 6:51 am
Location: Las Vegas, NV

Load dll in domain and CreateInstance

Postby TooTallTommyT » Wed Sep 12, 2018 7:19 pm

If a .dll was compiled based on the CSHTML5 references, could a person theoretically do something like this?

Code: Select all

 
var byte[] asmBytes = GetBytesFromAssemblyFile();
var asm = AppDomain.CurrentDomain.Load( asmBytes );
var pluginType = ( IPluginInterface ) Activator.CreateInstanceFrom( asm.FullName, "NameOfConcreteType" );


I've already got the .dll file downloaded from a "plugin's" folder on my site. If a person could do the previous, then extending my application with my own pluggable code would be great. I have tried some of this already, but I am running into a few issues, so I wanted to ask before I spent too much time on something that may, or may not, be doable.

T.
It ain't easy being green!

TaterJuice
Posts: 110
Joined: Thu Mar 16, 2017 5:40 am
Contact:

Re: Load dll in domain and CreateInstance

Postby TaterJuice » Thu Sep 13, 2018 12:26 pm

Tommy,

I am just another developer, not affiliated with the Userware\CSHTML5 team, so I could definitely be wrong on this, but....

As far as I know, this is not possible due to transpiling, but will be possible once CSHTML5 is WebAssembly compatible.
For now, I think you would need to reference the compiled CSHTML5 library (dll) in a new project, then run that project and wait for the simulator to transpile the html\js output of your new project (which will include the html\js output from your referenced assembly).

The problem is that the CSHTML5 libraries in dll form are not compatible with the transpiled CSHTML5 output, so the html\js output cannot read html\js from a .NET dll. Once WebAssembly compatibility is available, this should work because you won't be transpiling your .NET and C# to html\js - it will be native .NET running in WebAssembly.

The rest of your code should remain the same. You would still use Activator.CreateInstance with the Assembly\Assembly.FullName and Type\TypeName.

Note to @JS-Support: Please correct me if I'm wrong - I don't want to mislead anyone.

User avatar
TooTallTommyT
Posts: 15
Joined: Tue Aug 21, 2018 6:51 am
Location: Las Vegas, NV

Re: Load dll in domain and CreateInstance

Postby TooTallTommyT » Thu Sep 13, 2018 1:38 pm

Hey Tater!!

I appreciate the response. I was hoping that since both the "AppDomain.CurrentDomain.Load( )" and the "Activator.CreateInstanceFrom()" methods were available in my project that they had figured out a way to do it already.

Since it takes a fair amount of time to load my app, even as small as it is ( even with gzip compression on), my intent was, besides trying make a modular/plugable system, to essentially do a lazy load and only pull down parts of the app as it was needed. This would make the initial load faster, and keep bandwidth down.

We'll see what the man has to say :D
It ain't easy being green!


Return to “General Discussion and Other”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest