IOException when using EF Core model
When referencing an EF Core model, I get regular IOExceptions with a message "The process cannot access the file 'PATH_TO_DLL' because it is being used by another process"
I guess this is because I have the solution open in Visual Studio, and am running the code. However, I need to do that, as I develop and test in VS, and use LinqPad to double-check the database, and make manual changes as 'm developing.
Is there a way to avoid this error? Thanks
Comments
Argh, it's getting worse! I stopped running in VS whilst writing some tests, and I'm still getting these exceptions.
Not only that, but the modal pop-up appears BEHIND the LinqPad window, making it even more annoying to dismiss.
Take a look at the stack trace in %localappdata%\linqpad\logs.linqpad7. Does it include EFCore.StaticDriver.GetMaximumSupportedFrameworkVersion?
Yup, here is the last entry in the log...
7.3.9 (X64) 2022-07-17T21:41:17.1821585+01:00 GuiAppHost
[MainThread] IOException - The process cannot access the file 'C:\Users\me\blah\mywebsite.Web\bin\Debug\net6.0\mywebsite.Web.dll' because it is being used by another process.
Source=System.Private.CoreLib
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.File.OpenRead(String path)
at LINQPad.Reflection.FastAssemblyReader..ctor(String path)
at LINQPad.Reflection.FastAssemblyReader.GetReferences(String path)
at LINQPad.Extensibility.DataContext.DataContextDriver.GetReferencedAssemblies(String assemblyPath)
at LINQPad.Drivers.EFCore.StaticDriver.GetMaximumSupportedFrameworkVersion(IConnectionInfo cxInfo)
Try the latest beta and let me know whether it fixes the problem:
https://www.linqpad.net/linqpad7.aspx#beta
All seems good so far. Had it open for a few hours now, and haven't seen the exception once
Any idea when this version is going be released in full (ie not beta)?
Thanks
August.
Great, not too long then!
Thanks
The exception just happened again with the beta. However, the log file shows a different error...
7.4.6 (X64) 2022-07-20T18:09:32.3256274+01:00 GuiAppHost
[MainThread] IOException - The process cannot access the file 'C:\Users\MyUser\My project\Web site\MyProject.Web\bin\Debug\net6.0\MyProject.Web.dll' because it is being used by another process.
Source=System.Private.CoreLib
-Microsoft.Win32.SafeHandles.SafeFileHandle Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions) offset: 0x0
-Microsoft.Win32.SafeHandles.SafeFileHandle Microsoft.Win32.SafeHandles.SafeFileHandle Open(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, Int64) offset: 0x43
-System.IO.Strategies.OSFileStreamStrategy Void .ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, Int64) offset: 0x85
-System.IO.FileStream Void .ctor(System.String, System.IO.FileMode, System.IO.FileAccess) offset: 0x10
-LINQPad.Reflection.FastAssemblyReader Boolean IsManaged(System.String) offset: 0x1
-LINQPad.ReferenceSet NuGet.Versioning.NuGetVersion GetAspNetCoreVersionFromReferences(System.String) offset: 0x9
-LINQPad.ReferenceSet LINQPad.ReferenceSet Get(LINQPad.Extensibility.DataContext.DCDriverLoader, LINQPad.Repository, LINQPad.QueryCore, System.String, System.IO.TextWriter, System.Collections.Generic.List
1[LINQPad.NuGetInterop.PackageInfo], System.Collections.Generic.List
1[LINQPad.NuGetPackageRef]) offset: 0x4DC-LINQPad.ReferenceSet LINQPad.ReferenceSet ForQuery(LINQPad.QueryCore, System.IO.TextWriter, System.Collections.Generic.List
1[LINQPad.NuGetInterop.PackageInfo], System.Collections.Generic.List
1[LINQPad.NuGetPackageRef]) offset: 0x18-LINQPad.QueryCore LINQPad.ReferenceSet get_CombinedQueryReferences() offset: 0xA2
-LINQPad.UI.QueryControl Void UpdateMissingNuGetWarning() offset: 0x2
-LINQPad.UI.QueryControl Void PullData(LINQPad.QueryChangedEventArgs) offset: 0x218
-LINQPad.UI.QueryControl Void _query_QueryChanged(System.Object, LINQPad.QueryChangedEventArgs) offset: 0x14
-LINQPad.QueryCore Void OnQueryChanged(Boolean, LINQPad.QueryChangedEventArgs) offset: 0xFF
-LINQPad.RunnableQuery Void OnQueryChanged(Boolean, LINQPad.QueryChangedEventArgs) offset: 0xD
-LINQPad.QueryCore+ChangeTx Void Dispose() offset: 0x31
-LINQPad.QueryCore Void ForceRefresh(Boolean, Boolean, Boolean, Boolean) offset: 0x1A
-LINQPad.UI.QueryControl Void NotifyOfReferenceChange() offset: 0x6
-LINQPad.UI.MainForm Void StaticSchemaRepositoryChanged(LINQPad.Repository) offset: 0x59
-LINQPad.UI.MainForm+<>c__DisplayClass120_0 Void b__0() offset: 0x0
-System.Windows.Forms.Control Void InvokeMarshaledCallbackHelper(System.Object) offset: 0x35
-System.Threading.ExecutionContext Void RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) offset: 0x87
-System.Runtime.ExceptionServices.ExceptionDispatchInfo Void Throw() offset: 0x11
-System.Windows.Forms.Control Void InvokeMarshaledCallbacks() offset: 0xE9
First Chance Data:
-Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(fullPath,mode,access,share,options) offset=0x0
-Microsoft.Win32.SafeHandles.SafeFileHandle.Open(fullPath,mode,access,share,options,preallocationSize) offset=0x43
-System.IO.Strategies.OSFileStreamStrategy..ctor(path,mode,access,share,options,preallocationSize) offset=0x85
-System.IO.FileStream..ctor(path,mode,access) offset=0x10
-LINQPad.Reflection.FastAssemblyReader.IsManaged(fileName) offset=0x1
-LINQPad.ReferenceSet.GetAspNetCoreVersionFromReferences(path) offset=0x9
-LINQPad.ReferenceSet.Get(driverLoader,repository,query,runtimeVersionForDataContext,logger,allNuGetPackagesLog,nuGetFamiliesLog) offset=0x4DC
-LINQPad.ReferenceSet.ForQuery(query,logger,allNuGetPackagesLog,nuGetFamiliesLog) offset=0x18
-LINQPad.QueryCore.get_CombinedQueryReferences() offset=0xA2
-LINQPad.UI.QueryControl.UpdateMissingNuGetWarning() offset=0x2
-LINQPad.UI.QueryControl.PullData(changeInfo) offset=0x218
-LINQPad.UI.QueryControl._query_QueryChanged(sender,e) offset=0x14
-LINQPad.QueryCore.OnQueryChanged(flagAsModification,args) offset=0xFF
-LINQPad.RunnableQuery.OnQueryChanged(flagAsModified,args) offset=0xD
-LINQPad.QueryCore+ChangeTx.Dispose() offset=0x31
-LINQPad.QueryCore.ForceRefresh(queryTextChange,referenceChange,cxChange,otherChangeAffectingCompilation) offset=0x1A
-LINQPad.UI.QueryControl.NotifyOfReferenceChange() offset=0x6
-LINQPad.UI.MainForm.StaticSchemaRepositoryChanged(repository) offset=0x59
-LINQPad.UI.MainForm+<>c__DisplayClass120_0.b__0() offset=0x0
-System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(obj) offset=0x35
-System.Threading.ExecutionContext.RunInternal(executionContext,callback,state) offset=0x87
-System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() offset=0x11
Any ideas? Thanks again
Thanks - I've added a guard for this, too, in the latest beta, via fault-tolerant cache. There may be other cases where such an error pops up although not all cases are practical to guard.
Thanks, will try that and see how I get on.
Just to let you know that after a couple of months, I haven't had that exception at all, so it looks like it's all fixed.
Thanks
Great - thanks for the heads-up.