Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having issues with hot reloading and locked DLLs #93

Closed
KatoStoelen opened this issue Dec 6, 2019 · 8 comments · Fixed by #109
Closed

Having issues with hot reloading and locked DLLs #93

KatoStoelen opened this issue Dec 6, 2019 · 8 comments · Fixed by #109
Assignees
Labels
bug Something isn't working
Milestone

Comments

@KatoStoelen
Copy link
Contributor

Describe the bug
I can't seem to get hot reloading to work. The plugin DLLs are locked by dotnet.exe even with EnableHotReload = true.

The hot-reload sample in this repository yielded the same results.

Using .NET Core SDK v3.1.100 on Windows.

To Reproduce
Steps to reproduce the behavior:

  1. Install .NET Core SDK v3.1.100 on Windows
  2. Clone this (DotNetCorePlugins) repository
  3. Run /samples/hot-reload/run.sh
  4. Output:
run.sh: Use CTRL+C to exit
TimestampedPlugin: this plugin was compiled at 9:05:24 a.m.
run.sh: Rebuilding plugin...

C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(155,5): warning MSB3026: Could not copy "C:\Source\DotNetCorePlugins\.build\obj\TimestampedPlugin\Debug\netstandard2.0\TimestampedPlugin.dll" to "C:\Source\DotNetCorePlugins\samples\hot-reload\bin\plugins\TimestampedPlugin\TimestampedPlugin.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Source\DotNetCorePlugins\samples\hot-reload\bin\plugins\TimestampedPlugin\TimestampedPlugin.dll' because it is being used by another process.

Expected behavior
The plugin DLL is successfully overwritten and the PluginLoader gets reloaded.

@KatoStoelen KatoStoelen added the bug Something isn't working label Dec 6, 2019
@natemcmaster natemcmaster added the help wanted Extra attention is needed label Dec 7, 2019
@natemcmaster
Copy link
Owner

I don't have a Windows machine to debug this, so help would be appreciated in understanding why this is working on macOS and not Windows.

The plugin DLLs are locked by dotnet.exe

How do you know this? The log output in the repro you shared just says "because it is being used by another process."

@Andale-online
Copy link

This may occur in many circumstances. Even an open explorer.exe pointing to that directory may have a lock on files. I think there are some tools like sysinternals process explorer, which can show you who's locking the file.

@KatoStoelen
Copy link
Contributor Author

Previously, I've used such tools for figuring out which process is locking some file. However, while trying to delete the plugin DLL I figured out that Windows actually tells you which process is locking the file, nowadays.

From the hot-reload sample (./run.sh):
image

From my own custom built host (executed with dotnet path/to/myhost.dll):
image

It's very deterministic. Disposing the PluginLoader makes no difference either. The process needs to be stopped to unlock the DLL.

@Andale-online
Copy link

I'm on Win10 / VS2019 - does that fit? Think I'm gonna try the sample later. We will see...

@KatoStoelen
Copy link
Contributor Author

KatoStoelen commented Dec 10, 2019

Thanks @Andale-online. I'm eager to hear about the results :)

Personally, I do not have VS2019 installed, but I can't see any reason why that should make a difference? I guess the .NET Core runtime/SDK version is the most important?

@natemcmaster
Copy link
Owner

Thanks for the report @KatoStoelen - I setup a Windows VM so I could repro, and have prepared a fix: #108. I'm planning to release the fix soon as 0.3.2

@natemcmaster natemcmaster removed the help wanted Extra attention is needed label Dec 15, 2019
@KatoStoelen
Copy link
Contributor Author

Thanks for fixing this @natemcmaster - awesome work.

I did however stumple upon a similar issue with Microsoft.Data.SqlClient and sni.dll (a plugin accessing a database). sni.dll is still locked by the host process. I'm guessing the loading of unmanaged DLLs are now slightly different than managed DLLs? Would it be possible to implement the same fix for loading unmanaged DLLs?

@natemcmaster
Copy link
Owner

@KatoStoelen - can you open a separate issue for that? I don't think it's currently possible to hot reload unmanaged libraries using AssemblyLoadContext, but we can investigate workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants