FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

EmbeddedResource seems to be ignored for the XML Type Provider

Open rabejens opened this issue 5 years ago • 6 comments

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 avatar Mar 23 '20 07:03 rabejens

@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:

  1. I am using XML Schema File (".xsd") instead of sample XML.
  2. 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 avatar Apr 07 '20 18:04 ArtemyB

@ArtemyB's fix worked for me, note that the EmbeddedResource string appears to be case-sensitive with regards to the file names

MaybeSacred avatar Dec 10 '20 13:12 MaybeSacred

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 avatar Apr 26 '21 11:04 Evangelink

@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).

ArtemyB avatar May 03 '21 09:05 ArtemyB

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

sproott avatar Apr 25 '24 09:04 sproott

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?

sproott avatar Apr 25 '24 09:04 sproott