|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XmlSerializer for a type in dynamically loaded assemblyI 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. 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 Show quote "kishore" <vkbul***@gmail.com> wrote in message news:1154632511.401404.248460@75g2000cwc.googlegroups.com... > 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. > 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 :) Show quote "Greg Young" <druckdruckREMOVEgo***@hotmail.com> wrote in message news:eIz%23%23JztGHA.2392@TK2MSFTNGP05.phx.gbl... > 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" <vkbul***@gmail.com> wrote in message > news:1154632511.401404.248460@75g2000cwc.googlegroups.com... >> 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. >> > > 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 Young wrote: Show quote > 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" <druckdruckREMOVEgo***@hotmail.com> wrote in message > news:eIz%23%23JztGHA.2392@TK2MSFTNGP05.phx.gbl... > > 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" <vkbul***@gmail.com> wrote in message > > news:1154632511.401404.248460@75g2000cwc.googlegroups.com... > >> 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. > >> > > > > 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 kris1090 wrote: Show quote > 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 Young wrote: > > 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" <druckdruckREMOVEgo***@hotmail.com> wrote in message > > news:eIz%23%23JztGHA.2392@TK2MSFTNGP05.phx.gbl... > > > 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" <vkbul***@gmail.com> wrote in message > > > news:1154632511.401404.248460@75g2000cwc.googlegroups.com... > > >> 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. > > >> > > > > > > Why can you not just use loadfrom where it could find ands properly
reference your assembly? Show quote "kris1090" <vkbul***@gmail.com> wrote in message news:1154640189.894617.300020@75g2000cwc.googlegroups.com... > 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 > > kris1090 wrote: >> 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 Young wrote: >> > 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" <druckdruckREMOVEgo***@hotmail.com> wrote in message >> > news:eIz%23%23JztGHA.2392@TK2MSFTNGP05.phx.gbl... >> > > 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" <vkbul***@gmail.com> wrote in message >> > > news:1154632511.401404.248460@75g2000cwc.googlegroups.com... >> > >> 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. >> > >> >> > > >> > > > No you can't the compiler when run does not see your assembly in memory.
Show quote "kris1090" <vkbul***@gmail.com> wrote in message news:1154637675.879173.282450@p79g2000cwp.googlegroups.com... > 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 Young wrote: >> 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" <druckdruckREMOVEgo***@hotmail.com> wrote in message >> news:eIz%23%23JztGHA.2392@TK2MSFTNGP05.phx.gbl... >> > 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" <vkbul***@gmail.com> wrote in message >> > news:1154632511.401404.248460@75g2000cwc.googlegroups.com... >> >> 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. >> >> >> > >> > > |
|||||||||||||||||||||||