Strange stack trace...

88 views
Skip to first unread message

Isaac Sherman

unread,
Feb 25, 2022, 11:40:29 AM2/25/22
to libplctag
I've been having a problem lately where I've started getting this stack trace from PLC tag... I manufactured this one by opening a copy of the process, but the error is usually access denied (I suspect because I'm running in the Program Files directory).  
Is there a way around this apparent dumping of the dll to disk?  Can I force it to write into a temp file location where I do have access?

The process cannot access the file 'C:\<snipped out path>\plctag.dll' because it is being used by another process.

   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)

   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

   at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes)

   at System.IO.File.WriteAllBytes(String path, Byte[] bytes)

   at libplctag.NativeImport.LibraryExtractor.ExtractAppropriateLibraryToDirectory(String outputDirectory)

   at libplctag.NativeImport.LibraryExtractor.Init(Boolean forceExtract)

   at libplctag.NativeImport.plctag.ExtractLibraryIfRequired()

   at libplctag.NativeImport.plctag.plc_tag_create(String lpString, Int32 timeout)

   at libplctag.NativeTag.plc_tag_create(String lpString, Int32 timeout)

   at libplctag.NativeTagWrapper.Initialize()

   at libplctag.NativeTagWrapper.InitializeIfRequired()

   at libplctag.NativeTagWrapper.Read()

   at libplctag.Tag.Read()

   at libplctag.Tag`2.Read()

<snipped out my code>

Isaac Sherman

unread,
Feb 25, 2022, 3:03:49 PM2/25/22
to libplctag
Never mind, I found the answer.  For anyone curious, in the .NET adapter, they embed the dll within the dll that ships with the nuget package.  This is then extracted and called externally.  The problem was the default behavior was to always overwrite the file.  Luckily, they made an easy way to change the default behavior, which inspecting the code quickly revealed.  I love open source projects!

vern van leuven

unread,
Mar 2, 2022, 9:25:12 AM3/2/22
to libplctag
Hi,

Could you please share more detail on how you corrected the problem? I might be experiencing a similar issue. When I try to run two instances of my application, I get an error "The process cannot access the file ...\plctag.dll because it is being used by another process."

Thanks, Vern

Isaac Sherman

unread,
Mar 3, 2022, 10:57:16 AM3/3/22
to libplctag
Sure.  It's the same feature.  

If you set libplctag.NativeImport.plctag.ForceExtractLibrary to false, you should be good to go.  It will still expect the file to exist, though, so make sure you supply it with a copy.  The easiest way to do that is to hang on to the version that gets extracted the first time and just keep that in the folder you're running from. 

vern van leuven

unread,
Mar 3, 2022, 3:36:17 PM3/3/22
to libplctag
That did the trick. Thanks!
Reply all
Reply to author
Forward
0 new messages