SwaggerProvider icon indicating copy to clipboard operation
SwaggerProvider copied to clipboard

A temp dll already in use?

Open Thorium opened this issue 11 months ago • 5 comments

Many times when I try to build a project using SwaggerProvider, the build fails for a temporary dll being unable to access. If I retry the second time, it works fine. Can this be because, for example, the design-time and the compile-time try to access the same dll at the same time?

  • Could we use another dll instead?
  • Or maybe open the file with different read/write rights? (Overwrite.)
  • Or maybe use some synchronization concepts like MailBoxProcessor, or a simple one-time-retry of "wait 3 sec and retry"?

Or could these possibly cause the built dll be corrupted somehow?

This is a stack trace:

 error FS3033: The type provider 'SwaggerProvider.SwaggerTypeProvider' reported an error: Could not open file for writing (binary mode): C:\Users\(user)\AppData\Local\Temp\tmp837A.dll
 System.IO.IOException: The process cannot access the file 'C:\Users\(user)\AppData\Local\Temp\tmp837A.dll' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at ProviderImplementation.ProvidedTypes.BinaryWriter.writeBinaryAndReportMappings[a,b,c,d,e](String outfile, ILGlobals ilg, FSharpOption`1 pdbfile, a portablePDB, Boolean embeddedPDB, b embedAllSource, c embedSourceList, d sourceLink, Boolean emitTailcalls, Boolean deterministic, Boolean showTimes, e dumpDebugInfo, ILModuleDef modul)

Thorium avatar Jan 27 '25 14:01 Thorium

It may happen because we cache provided assemblies https://github.com/fsprojects/SwaggerProvider/blob/master/src/SwaggerProvider.DesignTime/Provider.OpenApiClient.fs#L88

in theory, different parts of ide may get the same cached assembly... Is it an error from the IDE or the console?

sergey-tihon avatar Jan 27 '25 15:01 sergey-tihon

Visual Studio 2022 build command, the build fails for this. It happens, e.g. with this library https://github.com/Thorium/ClearBank.Net, but it seems to happen on others as well.

Thorium avatar Jan 27 '25 15:01 Thorium

Do you have a similar issue with SQLProvider? Do you use caching inside?

sergey-tihon avatar Feb 01 '25 08:02 sergey-tihon

No issues there, but it's an erasing TP so I guess the compilation is different.

The caching if that is here: https://github.com/fsprojects/SQLProvider/blob/c4c8c384a47f7a5fc06d4fdf404d2b34f415ba13/src/SQLProvider.DesignTime/SqlDesignTime.fs#L1148

But also I don't have issues with FSharp.Data.

Thorium avatar Feb 02 '25 10:02 Thorium

I hit the same issue in Visual Studio, VSCode worked but only for version 2.1.0.

moloneymb avatar Sep 26 '25 21:09 moloneymb