External Component Exception Involving Shadow Copy Folder

168 views Asked by At

I have an application that is throwing an "External component has thrown an exception" error when trying to communicate from C# to C++ (correction: this is from C++ to C#). The C# solution involves a VSTO add-in that we think may be associated with the issue. Only users have been able to duplicate this issue and a temporary fix for the issue has been to clear out the "AppData\Local\assembly\dl3" shadow copy folder on their machine. It appears that the VSTO add-in is creating the dlls in that folder as shadow copies and there does not seem to be a way to prevent it.

Does anybody have any ideas about how to solve this issue?

Edit: The issue only occurs when a network update for the C++ application calling into the C# DLL occurs and another user is still logged in. If the shadow copy of the DLL created by the VSTO add-in doesn't exist then there are no issues. If the shadow copy does exist then the the two products won't be able to communicate until an update occurs to the C# application or if the shadow copy is removed. Using the VSTO add-in will cause the shadow copy to be recreated and break the connection again though.

1

There are 1 answers

0
user2483770 On

It turns out the issue is was a call to ...

Assembly.GetExecutingAssembly().Location 

The C++ solution called a C++ DLL that was a part of my C# solution which would load a C# assembly using ...

Assembly::LoadFrom(assemblyPathString)

That assembly would then make the offending call which would find a different shadow copied DLL instead of the original location. Switching the call to use ...

new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath 

... solved the issue. I'm not sure if the Uri and LocalPath portion were necessary or overkill.