XmlSerializer for a type in dynamically loaded assembly

K

kishore

Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this a
security problem?

How do i solve it?

Thanks in advance.
 
G

Greg Young

Also when dealing with codegen in general (this doesn't necesarily apply to
you).. it will create a temp file anyways during compilation ... it is a
question of whether or not it deletes it afterwords so you might as well
just keep the file if you are using XMLSerialization on those objects :)


Greg Young said:
The assembly needs to be on disk so the XMLserializer can reference it
when it generates the code to do your serialization.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

kishore said:
Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this a
security problem?

How do i solve it?

Thanks in advance.
 
K

kris1090

Thanks Greg. But is there any way i can point the XmlSerializer to
reference to the assembly i loaded in to memory rather than on disk.

Thanks

Greg said:
Also when dealing with codegen in general (this doesn't necesarily apply to
you).. it will create a temp file anyways during compilation ... it is a
question of whether or not it deletes it afterwords so you might as well
just keep the file if you are using XMLSerialization on those objects :)


Greg Young said:
The assembly needs to be on disk so the XMLserializer can reference it
when it generates the code to do your serialization.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

kishore said:
Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this a
security problem?

How do i solve it?

Thanks in advance.
 
K

kris1090

Also, is there any other way i can generate XML format other than
serialization if XMLSerializer is not going to work for pre-loaded
Assemblies. Please help.

Thanks
Thanks Greg. But is there any way i can point the XmlSerializer to
reference to the assembly i loaded in to memory rather than on disk.

Thanks

Greg said:
Also when dealing with codegen in general (this doesn't necesarily apply to
you).. it will create a temp file anyways during compilation ... it is a
question of whether or not it deletes it afterwords so you might as well
just keep the file if you are using XMLSerialization on those objects :)


Greg Young said:
The assembly needs to be on disk so the XMLserializer can reference it
when it generates the code to do your serialization.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this a
security problem?

How do i solve it?

Thanks in advance.
 
G

Greg Young

No you can't the compiler when run does not see your assembly in memory.

kris1090 said:
Thanks Greg. But is there any way i can point the XmlSerializer to
reference to the assembly i loaded in to memory rather than on disk.

Thanks

Greg said:
Also when dealing with codegen in general (this doesn't necesarily apply
to
you).. it will create a temp file anyways during compilation ... it is a
question of whether or not it deletes it afterwords so you might as well
just keep the file if you are using XMLSerialization on those objects :)


Greg Young said:
The assembly needs to be on disk so the XMLserializer can reference it
when it generates the code to do your serialization.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this a
security problem?

How do i solve it?

Thanks in advance.
 
G

Greg Young

Why can you not just use loadfrom where it could find ands properly
reference your assembly?


kris1090 said:
Also, is there any other way i can generate XML format other than
serialization if XMLSerializer is not going to work for pre-loaded
Assemblies. Please help.

Thanks
Thanks Greg. But is there any way i can point the XmlSerializer to
reference to the assembly i loaded in to memory rather than on disk.

Thanks

Greg said:
Also when dealing with codegen in general (this doesn't necesarily
apply to
you).. it will create a temp file anyways during compilation ... it is
a
question of whether or not it deletes it afterwords so you might as
well
just keep the file if you are using XMLSerialization on those objects
:)


The assembly needs to be on disk so the XMLserializer can reference
it
when it generates the code to do your serialization.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

Hi
I have an assembly which I load using Assembly.Load(bytes[]). Within
the Assembly i have a method which invokes XmlSerializer.serialize
method on a type. This type is also within the assembly.

However the serialize method throws an exception saying

Unable to generate a serializer for type MyNamespace.Classtype from
assembly <Unknown> because the assembly may be dynamic. Save the
assembly and load it from disk to use it with XmlSerialization

On a different machine the constructor for the serializer failed to
generate with following error:

Unable to generate a temporary class (result=1).
error CS0234: The type or namespace name 'xxxxx' does not exist in
the
class or namespace yyyy

Everything works fine if i load the assembly using LoadFrom. Is this
a
security problem?

How do i solve it?

Thanks in advance.
 

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