Cannot CreateInstance of Assembly after loading it with Assembly.Load(byte[])

D

Dmitriy Krasnikov

Hi everybody. It's probably something easy, but stops me dead on
tracks.
I have no problem CreateInstance or InvokeMember on constructor when I
am loading assembly using Assembly.LoadFile.
But if I use Assembly.Load(byte[]), I cannot Invoke constructor,
cannot Activator.CreateInstance - it gives be error "Exception were
thrown by target".
Please help.
 
J

Jon Skeet [C# MVP]

<Dmitriy Krasnikov <dmitriykrasnikov.remove this its for
Hi everybody. It's probably something easy, but stops me dead on
tracks.
I have no problem CreateInstance or InvokeMember on constructor when I
am loading assembly using Assembly.LoadFile.
But if I use Assembly.Load(byte[]), I cannot Invoke constructor,
cannot Activator.CreateInstance - it gives be error "Exception were
thrown by target".
Please help.

Well the first thing to do is see what exception has been thrown - look
at the InnerException property.
 
D

Dmitriy Krasnikov

<Dmitriy Krasnikov <dmitriykrasnikov.remove this its for
Hi everybody. It's probably something easy, but stops me dead on
tracks.
I have no problem CreateInstance or InvokeMember on constructor when I
am loading assembly using Assembly.LoadFile.
But if I use Assembly.Load(byte[]), I cannot Invoke constructor,
cannot Activator.CreateInstance - it gives be error "Exception were
thrown by target".
Please help.

Well the first thing to do is see what exception has been thrown - look
at the InnerException property.

Thank you. It gave more meaningfull message.
"Unable to generate a serializer for type wst.SqlMessage from assembly
<Unknown> because the assembly may be dynamic. Save the assembly and
load it from disk to use it with XmlSerialization."
Any workarounds possible? The problem is, if I load it from disk I
cannot delete it later and generate new.
 
J

Jon Skeet [C# MVP]

<Dmitriy Krasnikov <dmitriykrasnikov.remove this its for
Thank you. It gave more meaningfull message.
"Unable to generate a serializer for type wst.SqlMessage from assembly
<Unknown> because the assembly may be dynamic. Save the assembly and
load it from disk to use it with XmlSerialization."
Any workarounds possible? The problem is, if I load it from disk I
cannot delete it later and generate new.

I'm afraid I don't know - I haven't done much with serialisation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top