azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Could not find file 'C:\home\site\wwwroot\ref'.

Open XiaoshiSha opened this issue 1 year ago • 3 comments

I'm using package Microsoft.Azure.WebJobs.Extensions.OpenApi 1.4.0, and using ZipDeploy to deploy to Azure. But it returns the error mentioned in title when I send get request https://xxx.azurewebsites.net/api/swagger/ui.

After digging into a little bit, I find it's probably due to C:\home\site\wwwroot\ref is actually an empty folder, but C:\home\site\wwwroot\bin\ref has lots of dlls. So I tried to copy all dlls under bin\ref to ref, then ZipDeploy to Azure, problem solved.

I noticed function RenderSwaggerUI calls SetApplicationAssemblyAsync which has a default parameter appendBin = true. In Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions, it passes in false explictly, but in Microsoft.Azure.WebJobs.Extensions.OpenApi it uses default parameter true. I'm pretty sure I'm using the latter package, so don't understand why it didn't looks for bin\ref.

So my question is -

  1. Why it wants to look up in C:\home\site\wwwroot\ref?
  2. Shall I copy bin\ref to ref before deploying to Azure? is there any parameter to let dotnet publish dlls to both ref and bin\ref?
        [OpenApiIgnore]
        public static async Task<IActionResult> RenderSwaggerUI(
            [OpenApiHttpTriggerContext] OpenApiHttpTriggerContext openApiContext,
            HttpRequest req, ExecutionContext ctx, ILogger log)
        {
            log.LogInformation("SwaggerUI page was requested.");

            var request = new HttpRequestObject(req);
            var result = default(string);
            var content = default(ContentResult);
            try
            {
                var auth = await openApiContext.SetApplicationAssemblyAsync(ctx.FunctionAppDirectory)
                                        .AuthorizeAsync(request)
                                        .ConfigureAwait(false);

        public virtual async Task<IOpenApiHttpTriggerContext> SetApplicationAssemblyAsync(string functionAppDirectory, bool appendBin = true)
        {
            if (!this._dllpath.IsNullOrWhiteSpace())
            {
                return this;
            }

            var runtimepath = this.GetRuntimePath(functionAppDirectory, appendBin);
            var runtimename = await this.GetRuntimeFilenameAsync(functionAppDirectory);
            var dllpath = $"{runtimepath}{Path.DirectorySeparatorChar}{runtimename}";

            this._dllpath = dllpath;

            return this;
        }

XiaoshiSha avatar Aug 26 '22 05:08 XiaoshiSha

I'm seeing this same issue but with D:\home\site\wwwroot\refs.

kaelonR avatar Aug 29 '22 10:08 kaelonR

Same here. The error message I receive is: Could not find file 'C:\home\site\wwwroot\cs'.

My company's DevOps pipeline publishes the entire solution as well (we are working on changing that), so I applied the <IsPublishable>false</IsPublishable> fix to my test projects as described in a comment here.

Looking at the deployment directory in Console of the Function App, I see the following directory structure:

Directory of C:\home\site\wwwroot

06/01/2023  05:19 PM    <DIR>          Function1
06/01/2023  05:19 PM    <DIR>          Function2
06/01/2023  05:17 PM            27,981 MyApi.Business.deps.json
06/01/2023  05:17 PM            22,062 MyApi.DataAccess.deps.json
06/01/2023  05:17 PM             3,197 MyApi.Domain.deps.json
06/01/2023  05:19 PM    <DIR>          bin
06/01/2023  05:19 PM    <DIR>          cs
06/01/2023  05:19 PM    <DIR>          de
06/01/2023  05:19 PM    <DIR>          es
06/01/2023  05:19 PM    <DIR>          fr
06/01/2023  05:14 PM               349 host.json
06/01/2023  05:19 PM    <DIR>          it
06/01/2023  05:19 PM    <DIR>          ja
06/01/2023  05:19 PM    <DIR>          ko
06/01/2023  05:19 PM    <DIR>          pl
06/01/2023  05:19 PM    <DIR>          pt-BR
06/01/2023  05:19 PM    <DIR>          ru
06/01/2023  05:19 PM    <DIR>          runtimes
06/01/2023  05:19 PM    <DIR>          tr
06/01/2023  05:19 PM    <DIR>          zh-Hans
06/01/2023  05:19 PM    <DIR>          zh-Hant

Given the error message above, it looks like the extension is picking up on directory .\cs (the directory is empty).

Note: the Function App is configured to run from package (WEBSITE_RUN_FROM_PACKAGE = 1).

CNBoland avatar Jun 01 '23 19:06 CNBoland

Seems related to #332.

CNBoland avatar Jun 01 '23 21:06 CNBoland