Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmbeddedResource seems to be ignored for the XML Type Provider #1310

Open
rabejens opened this issue Mar 23, 2020 · 6 comments
Open

EmbeddedResource seems to be ignored for the XML Type Provider #1310

rabejens opened this issue Mar 23, 2020 · 6 comments

Comments

@rabejens
Copy link

rabejens commented Mar 23, 2020

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.

@ArtemyB
Copy link

ArtemyB commented Apr 7, 2020

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

@MaybeSacred
Copy link

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

@Evangelink
Copy link

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?

@ArtemyB
Copy link

ArtemyB commented May 3, 2021

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

@sproott
Copy link

sproott commented Apr 25, 2024

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
Copy link

sproott commented Apr 25, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants