2
Vote

Unable to copy DLL due to already in use by R

description

I am able to successfully run my C# class library from R using rClr, however if I attempt to clean and build by C# after calling it from my R scripts, the error below appears.
Unable to copy file "obj\x64\Debug\TestWithR.dll" to "bin\x64\Debug\TestWithR.dll". The process cannot access the file 'bin\x64\Debug\TestWithR.dll' because it is being used by another process.

Could not copy "obj\x64\Debug\TestWithR.dll" to "bin\x64\Debug\TestWithR.dll". Exceeded retry count of 10. Failed.
The only solution I have found is to restart RStudio. Is there a way for my scripts to detach from the DLL? This is a serious blocker for me right now.

comments

markty wrote Apr 28 at 1:51 AM

I believe this is down to the file being locked on assembly load in the framework. Not knowing how it works under the hood, a possible solution might be as mentioned here

markty wrote Apr 28 at 1:56 AM

I should add that, for myself, this issue prevents the use of automated deployment to a shared server unless all users close their RStudio sessions which can be a bit of an issue.