Skip to content

[Repo Assist] Fix #1310: GetSchema works correctly when EmbeddedResource is specified for XSD schemas#1619

Merged
dsyme merged 7 commits intomainfrom
repo-assist/fix-issue-1310-xsd-embedded-resource-466ae4f06439984d
Feb 23, 2026
Merged

[Repo Assist] Fix #1310: GetSchema works correctly when EmbeddedResource is specified for XSD schemas#1619
dsyme merged 7 commits intomainfrom
repo-assist/fix-issue-1310-xsd-embedded-resource-466ae4f06439984d

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated draft PR from Repo Assist, an AI assistant.

Summary

Fixes #1310XmlProvider with Schema = "..." and EmbeddedResource = "..." now generates a GetSchema() method that reads the XSD from the embedded resource at runtime, instead of failing with DirectoryNotFoundException because the design-time file path no longer exists.

Root Cause

In Helpers.fs, the GetSchema method was generated inside an if not parseResult.IsResource then guard. This guard was designed to suppress GetSample/GetSamples for providers that embed their sample at design time. However, Schema _ was also inside this guard, so when EmbeddedResource was correctly specified and the resource was found at design time (IsResource = true), GetSchema was never generated — leaving the type without any way to load the schema at runtime.

When EmbeddedResource was incorrectly specified (wrong assembly name or resource name), tryGetResource returned None and IsResource = false, so GetSchema was generated — but it baked in the design-time file path via asyncReadTextAtRuntimeWithDesignTimeRules. This path doesn't exist on the target machine, causing DirectoryNotFoundException.

Fix

GetSchema generation is now moved outside the if not parseResult.IsResource then block. A new IsResource branch reads the schema from the embedded resource at runtime:

if parseResult.IsResource then
    // Read XSD from embedded resource at runtime
    let parts = resource.Split(',')
    let asmName = parts.[0].Trim()
    let resName = parts.[1].Trim()
    <@
        let loadedAsm =
            System.AppDomain.CurrentDomain.GetAssemblies()
            |> Array.find (fun a -> a.GetName().Name = asmName)
        let stream = loadedAsm.GetManifestResourceStream(resName)
        new System.IO.StreamReader(stream) :> TextReader
    @>
    |> spec.CreateFromTextReaderForSampleList

The StreamReader/Stream is not wrapped in use here — its lifetime is managed by parseSchemaFromTextReader, which creates an XmlReader with CloseInput = true that disposes the underlying reader when schema compilation is complete.

Trade-offs

  • AppDomain.CurrentDomain.GetAssemblies() only finds already-loaded assemblies. Since GetSchema() is called from user code in the same assembly, that assembly is always loaded. This matches the semantics of the existing readResource design-time helper.
  • The fix does not change behaviour for the non-EmbeddedResource case (existing GetSample/GetSamples suppression logic is untouched).

Test Status

✅ All 248 existing tests pass (dotnet test tests/FSharp.Data.Tests/FSharp.Data.Tests.fsproj -c Release).

No new test was added because testing EmbeddedResource requires a compiled assembly with the resource embedded, which is difficult to set up in the existing test project. The fix follows the same pattern used in the rest of Helpers.fs for embedded-resource handling.

Generated by Repo Assist

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@de40494d3f62516449f458c4f8d8d2fe370708fe. View source at https://github.com/githubnext/agentics/tree/de40494d3f62516449f458c4f8d8d2fe370708fe/workflows/repo-assist.md.

When XmlProvider is used with Schema and EmbeddedResource, the EmbeddedResource
parameter was previously ignored at runtime because GetSchema was inside the
'if not parseResult.IsResource then' guard that suppressed it when a resource
was found at design time.

This fix moves GetSchema generation outside that guard and adds an IsResource
branch that reads the XSD from the embedded resource at runtime using
AppDomain.CurrentDomain.GetAssemblies().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

✅ Pull request created: #1619

@>
else
<@ new StringReader(valueToBeParsedOrItsUri) :> TextReader @>
| Schema _ -> () // GetSchema is generated below, outside this block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Add a test case for this fix

Copy link
Contributor

Copilot AI commented Feb 22, 2026

@dsyme I've opened a new pull request, #1620, to work on those changes. Once the pull request is ready, I'll request review from you.

@dsyme dsyme marked this pull request as ready for review February 22, 2026 19:10
* Initial plan

* Add test case for GetSchema with EmbeddedResource in XSD schemas

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

🤖 This is an automated note from Repo Assist.

The Windows CI failure on this PR is an infrastructure issue, not caused by the code changes.

The failing test is Don't throw exceptions on http error in Http.fs:75 — it makes a real outbound HTTP connection which is blocked by the Windows CI runner's network firewall. The same test is known to fail sporadically in this environment for the same reason.

All 248 unit tests, all 1 reference test, and all 485 design-time tests pass on Windows (0 failures). The build itself is clean.

This PR is safe to review and merge on its merits. @dsyme, please disregard the CI failure — it is unrelated to the GetSchema/EmbeddedResource fix.

Generated by Repo Assist

To install this workflow, run gh aw add githubnext/agentics/workflows/repo-assist.md@ee50a3b7d1d3eb4a8c409ac9409fd61c9a66b0f5. View source at https://github.com/githubnext/agentics/tree/ee50a3b7d1d3eb4a8c409ac9409fd61c9a66b0f5/workflows/repo-assist.md.

@dsyme
Copy link
Contributor

dsyme commented Feb 22, 2026

@copilot Fix this error from CI

Error: System.Collections.Generic.KeyNotFoundException : An index satisfying the predicate was not found in the collection.

  Failed GetSchema works for XmlProvider with Schema and EmbeddedResource [11 ms]
  Error Message:
   System.Collections.Generic.KeyNotFoundException : An index satisfying the predicate was not found in the collection.
  Stack Trace:
     at Microsoft.FSharp.Collections.ArrayModule.loop@722-39[T](FSharpFunc`2 predicate, T[] array, Int32 i) in D:\a\_work\1\s\src\fsharp\FSharp.Core\array.fs:line 723
   at FSharp.Data.Reference.Tests.XmlProvider.GetSchema works for XmlProvider with Schema and EmbeddedResource() in /home/runner/work/FSharp.Data/FSharp.Data/tests/FSharp.Data.Reference.Tests/XmlProvider.fs:line 8
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)


Copy link
Contributor

Copilot AI commented Feb 22, 2026

@dsyme I've opened a new pull request, #1623, to work on those changes. Once the pull request is ready, I'll request review from you.

…n search

Replace AppDomain.CurrentDomain.GetAssemblies() |> Array.find with
System.Reflection.Assembly.Load(asmName), which handles assemblies
not yet loaded into the AppDomain (e.g. when called from a test project).

Suggested in Copilot SWE PR #1623.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

✅ Commit pushed: f9687ff

Copilot AI and others added 2 commits February 22, 2026 22:06
…n search (#1623)

* Initial plan

* Fix CI: Use Assembly.Load instead of AppDomain.GetAssemblies for EmbeddedResource schema

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
@dsyme dsyme merged commit cf14933 into main Feb 23, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-1310-xsd-embedded-resource-466ae4f06439984d branch February 23, 2026 00:16
github-actions bot added a commit that referenced this pull request Feb 23, 2026
Add entries for:
- #1613: CSS pseudo-class NotSupportedException fix (#1383)
- #1617: ConvertDateTimeOffset xs:dateTime fallback fix (#1437)
- #1618: Microsoft.Build security bump
- #1619: XmlProvider EmbeddedResource GetSchema fix (#1310)
- #1621: StrictBooleans parameter for CsvProvider
- #1625: CsvProvider.InferRows multiline quoted field fix (#1439)
- #1626: XSD group reference cycle guard (#1419)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EmbeddedResource seems to be ignored for the XML Type Provider

2 participants