0

I have been following this MSDN example and when I try to compile it, it throws this exception: An attempt was made to load a program with an incorrect format. (0x8007000B) everything seems to work fine until it reaches xmlDoc.Load("test.xml"); part. I searched around for a while and can't find an answer.

Did I miss something? Does anyone know why this is coming up?

  • Do any of the answers at [“An attempt was made to load a program with an incorrect format” even when the platforms are the same](https://stackoverflow.com/questions/2023766/an-attempt-was-made-to-load-a-program-with-an-incorrect-format-even-when-the-p) help? – Andrew Morton Jun 29 '20 at 10:24
  • @AndrewMorton No, not really. I have read that question before posting this. But I think my problem is not caused by 32-bit and 64-bit processes. It's coming up when I try to `Load()` the XML file into the `XmlDocument` file. – Enkhbold Munkhbold Jun 29 '20 at 11:10
  • But I will try it with x86 just in case. Thanks for replying btw. – Enkhbold Munkhbold Jun 29 '20 at 11:15
  • @AndrewMorton I've posted an answer. And thanks, it works but I don't know as to why it is necessary to run it as x86 specifically though. Can you tell me why? – Enkhbold Munkhbold Jun 29 '20 at 11:39
  • I have no idea. Especially as the code has already run `Dim xmlDoc As New XmlDocument()` by that point. But maybe it doesn't load the assembly with the XML stuff in until it actually does something with it, and somehow it's trying to use a 32-bit assembly when it shouldn't. That's only speculation. – Andrew Morton Jun 29 '20 at 12:03

1 Answers1

0

Setting the Platform target in Properties -> Build as x86 rather than "any CPU" solves it.

Dunno why XML file needs to be loaded with 32-bit only tho.