fsprojects / FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
http://fsprojects.github.io/FSharp.Configuration/
Other
114 stars 63 forks source link

ResX: The invoked member is not supported in a dynamic assembly #140

Open 2moveit opened 6 years ago

2moveit commented 6 years ago

I tried the ResXProvider like described on the doc page just with my resx file. I do get intellisense so it seems to work. When I start the four lines of the script in the fsi of VS 2017 I do get the following error:

System.NotSupportedException: The invoked member is not supported in a dynamic assembly.
   at System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames()
   at System.Resources.ManifestBasedResourceGroveler.CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name)
   at System.Resources.ManifestBasedResourceGroveler.GetManifestResourceStream(RuntimeAssembly satellite, String fileName, StackCrawlMark& stackMark)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name)
   at FSharp.Configuration.ResXProvider.readValue[a](String resourceName, Assembly assembly, String key)
   at <StartupCode$FSI_0004>.$FSI_0004.main@()
Stopped due to error

I sounds that it is not possible to start it from the fsi, is it? If not a hint on the website would be great but more likely I missed something.

sergey-tihon commented 6 years ago

I am not an author, but I know that TP loads the resource from executing assembly - https://github.com/fsprojects/FSharp.Configuration/blob/master/src/FSharp.Configuration/ResXProvider.fs#L39 so TP expects that resource is compiled into assembly, that probably means that it does not work from fsi.

Do you know how to load resources rather than using ResourceManager? https://github.com/fsprojects/FSharp.Configuration/blob/master/src/FSharp.Configuration/ResXProvider.fs#L25

It not ... we probably should update docs

2moveit commented 6 years ago

Maybe it's possible with CreateFileBasedResourceManager, But then the .resx file needs to be "compiled" with resgen to a ..resource file. Is that possible to do in the type provider?

2moveit commented 6 years ago

I just moved the type provider in the .fs file. You can reference the dll that uses the type provider in the .fsi script and it will work.

I had one gotcha. I got a MissingManifestResourceException. I created the .resx files with VS 15.6.7. There is a new option (e.g. not available in 15.2) in the project properties -> Application -> Resources -> Use standard resource names. This has to be deactivated.

I guess many people usually start testing type providers in the fsi. So I would recommend that the docs should mention that while no other solution is implemented.

I just wonder how this output can work? https://github.com/fsprojects/FSharp.Configuration/blob/9b84f3e9dc873a7f3c9c38cdb97133b0bb556d01/docs/content/ResXProvider.fsx#L37