0

I'm trying to read in the text (as a string) of an XML file from my Resources. The XML file is named MyXMLResourceFile.resx.

I tried using the C# way using

let myFile : string = Properties.Resources.MyXMLResourceFile

but it is giving me the error (under Properties):

The namespace or module 'Properties' is not defined.

I'm assuming I'm missing an open but have no idea what it would be.

Sorry, I'm still pretty new to F# coming from VB.

Additional information:

I made the resx file myself per this SO answer I then looked to see how others accessed it. In C# they did Properties.Resources.XXXX per this project I saw you could use ResourceManager but didn't see any method to read the whole file directly into a string.

Community
  • 1
  • 1
Jon49
  • 4,444
  • 4
  • 36
  • 73

1 Answers1

1
The namespace or module 'Properties' is not defined.

That's because the namespace Properties is not defined. You probably brought the resx file from another project. Open the associated .Designer file, if it doesn't appear in the F# project, open it up in the original project. You will see a namespace with and a bunch of C# code, assuming the original project was in C#. The namespace of this file has to be the same namespace of the project where you are trying to call it.

But, since this is C# code, it won't run on a F# project. You have two choices: use a code generator to generate the associated .Designer class in F# code with the Properties namespace, (I don't know if such generator exists); or pre-compile the resx in the original project and reference it as a dll from your F# project, then you can access it with ResourceManager.

sker
  • 17,842
  • 8
  • 37
  • 41
  • See "Additional Information" in my comment. I actually think I might have thought of a way to do it - make the XML equal to a variable then grab the variable, maybe? I don't know if that would work since it uses new lines. – Jon49 Jul 12 '13 at 14:57
  • You second link shows you how to do it with ResourceManager. Isn't that what you want? Or do you want to read the actual XML into a string, and not the values? – sker Jul 12 '13 at 15:34
  • Yes, I need to read it into a string and not the values. I'll be using FSharp.Data to read the values of a dynamic XML. I just need the embedded XML as a template for FSharp.Data. http://fsharp.github.io/FSharp.Data/library/XmlProvider.html – Jon49 Jul 12 '13 at 16:43
  • If you want to read the xml as a string, wouldn't File.ReadAllText solve the problem? – sker Jul 12 '13 at 20:01
  • Yes, but I was hoping to embed the file. I suppose I don't need to though - although it would be preferable. I didn't realize it would be so difficult to embed. – Jon49 Jul 12 '13 at 20:31
  • I see what you're trying to do. Did you try this http://stackoverflow.com/a/2820420/9776 ? Seems to be what you need, it's in C#, but there's no reason why it shouldn't work in F#. – sker Jul 13 '13 at 06:11
  • That looks like it. I'll be out of town for over a week without my computer so I'll look at it then. I'll let you know how it works when I get back and mark you correct if it does. Thanks for your help! – Jon49 Jul 14 '13 at 20:49