-
Notifications
You must be signed in to change notification settings - Fork 289
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
Error opening a library that uses JsonProvider with an embedded resource #1191
Comments
@ScottShingler just had the same issue too, but with P.S. This SO answer helped me. |
I'm experiencing the same issue with the JsonProvider and the workaround doesn't seem to work for me. Lib
Console App
Build Error
The boards.json file is in the root and lib compiles successfully. |
@fischgeek have you added "boards.json" to the project as an embedded resource? |
Isn't that what this is doing Should I be manually loading this as a resource file in the Lib? |
@fischgeek as I understand this provider parameter only tells the provider to look for the sample JSON-file among the project resources. So if the provider can't find the resource (because it wasn't included in the assembly), it will throw the error. I suspect the phrase |
Right, I understand that, however the Library will compile successfully which lead me to believe it was working as is. I'm still not clear as to if I need to embed the json file in the library project AND declare the type from the file path or if I need to embed the resource json file in the calling project. |
@fischgeek not in the calling project. You should embed it only in the library where the type for provider is declared. And also you should specify the provider parameter as you've done initially. After that you should be able to use the library with the types, generated by type provider, without any issues (and without any worries about the sample file). |
@ArtemyB Thank you! I'll give that a try! Might be out of context here, but is there anyway to alias the result of |
@fischgeek by "my own type derived from it" you mean inheritance or what? I don't understand completely what are you trying to achieve. P.S.: I'll try to guess something about aliasing and |
Okay. I apologize for nudging this one again. I gave up after a while and now I'm back at it trying to figure it out. Here's what I have done so far but still get the error. The Library Project
The Console Project
Error: The type provider 'ProviderImplementation.JsonProvider' reported an error: An index satisfying the predicate was not found in the collection. What am I doing wrong? |
@fischgeek , as I've understood your sample JSON is located in the directory "Samples". In that case |
@ArtemyB , thanks for pointing that out. However, I'm afraid the console app still doesn't compile. I also updated my comment with the change you suggested. |
@fischgeek and when you reference the project, not just the DLL, does all work? |
@ArtemyB actually, no. It doesn't. Interesting. |
@fischgeek what are you trying to do when you're calling |
@ArtemyB The parameter example data "boardId" was a bad example. It would in-fact be the string representation of the json in board.json. I just didn't want to shove all that into a comment as it is rather large. But, it does match. When I normally do this in the same project I use |
FWIW - I found that if I keep my json samples in a directory outside both projects, and provide the full path in the library project it seems to work. This is good enough for me for now. Thanks @ArtemyB |
@fischgeek ok, it's already good that you've made it work at least in such way. But I still don't know why it doesn't works in the initial way, because in my case with XML provider (for XML Schema, not sample) all works as intended, even when I reference the library as NuGet-package. And your last version seems to me the same as mine (relying on your description of course). |
I was struggling with that and things were not working until I found [this comment](fsprojects#1191 (comment)) noting that point about project file. I think it would be useful for others as well.
I've encountered some strange behaviour when trying to open a library that uses a JsonProvider with an embedded resource.
Given then following module defined in a separate library:
And the following program that references and consumes
MyLib
:I get the following compilation error:
For this simple example, there is a workaround to avoid this error: Instead of opening
MyLib
, use the fully-qualified name when referencingloadMyConfig
(i.e.MyLib.loadMyConfig
).There is also an Intellisense issue regardless of whether the workaround is used: If you attempt to dot into
MyLib
(i.e. typeMyLib.
), Intellisense will show the same error reported above.I have put together a repro here: https://github.com/ScottShingler/JsonProviderEmbeddedRepro
I should also mention that I'm experiencing the same compilation error in another project, but the workaround of not opening the library module is not solving it. Unfortunately I am unable to share that code since it's proprietary, but I expect the root cause of this issue should be related.
The text was updated successfully, but these errors were encountered: