EmbeddedResource seems to be ignored for the XML Type Provider
I am using the XML Type Provider with FSharp.Data. I have a line like this:
type internal SomethingFromXML = XmlProvider<"./Sample.xml", EmbeddedResource="MyLib, Sample.xml">
I set the Sample.xml to "Embedded Resource, Do Not Copy".
I packed the MyLib to a NuGet package and used it in another program. But when I now execute it, I get a DirectoryNotFoundException saying it can't find C:\Path\To\My\SolutionWithMyLib\MyLib\Sample.xml
So, it seems to ignore the EmbeddedResource directive. Is that not supported with the XML Provider?
Followup
I found #1191 and changed the EmbeddedResource to MyLib, MyLib.Sample.xml but that did not change anything.
@rabejens I am also using XML Type Provider but do not have any errors (however there were some a couple of months ago). I've also tried packing my library with TP-provided types into NuGet-package and it also has worked for me. Based on your message it seems that your actions should be correct. The only differences between your case and mine:
- I am using XML Schema File (".xsd") instead of sample XML.
- My sample file located in the subfolder. I.e. if the subfolder name is "Data" then my TP call looks like that:
type XmlData = XmlProvider<Schema = "Data/MySchema.xsd", EmbeddedResource = "MyLib, MyLib.Data.MySchema.xsd">
@ArtemyB's fix worked for me, note that the EmbeddedResource string appears to be case-sensitive with regards to the file names
Hi there,
I am facing the same issue... I have tried to apply the previous comments but nothing is working. It seems to always rely on the local file, so when I get rid of it, I get an exception.
Anyone with some idea?
@Evangelink hi, can't suggest anything else for now -- I'm still using the library which I created then and all is done according to the description in my comment above. But FSharp.Data dependency hasn't been updating since then and is v3.3.3 -- maybe something has changed in the newer version 🤔
However I've noticed one more detail not mentioned there previously -- the .xml/.xsd file should be added as an embedded resource to the project, so its' "Build action" property should be in "EmbeddedResource" state or, in other words, in project-file its entry should look like <EmbeddedResource Include="MyDataDirectory\MyXmlSchema.xsd"></EmbeddedResource> (if file's relative path is "MyDataDirectory\MyXmlSchema.xsd" of course).
Hi there,
I am facing the same issue... I have tried to apply the previous comments but nothing is working. It seems to always rely on the local file, so when I get rid of it, I get an exception.
Anyone with some idea?
I had the same issue, re-checked the embedded resource path and everything was OK. After some debugging, I realized I had defined the provided type inside a namespace, not a module, which I realized could mess with the type's assembly and therefore embedded resources. After putting the type into a module, everything works.
EDIT: nevermind, it still doesn't work, probably tested it wrong
For me, the problem seems to arise when GetSchema is called. I've noticed in this section that the resource is not being taken into account. Shouldn't GetSchema also first try to load the embedded resource, or am I misunderstanding something?