Adding, removing and adding back the same assembly to IProjectAssembly, does not persist

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 4 years ago by Manoj
Version: 14.1.0610
Environment: Windows 7 (64-bit)
Avatar

Hi, 

 

I added the Assembly X.dll to the 

IProjectAssembly.AssemblyReferences.AddFrom("X.dll");

then I remove the Assembly X.dll from

IProjectAssembly.AssemblyReferences.Remove("X.dll");

If Now I try to add again the 

IProjectAssembly.AssemblyReferences.AddFrom("X.dll");

the above code runs successfully, but it is not in the collection, it does not adds it.

Please advice ASAP.

 

Thanks,

Manoj

Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Manoj,

Unfortunately that is a behavior of .NET when trying to reflection load an assembly in the same appdomain where an assembly of the same name was previously loaded. .NET effectively throws:

FileLoadException' occurred in mscorlib.dll

API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

It's an annoying restriction in .NET that many consider an unnecessary bug in the platform.

We have an item on our TODO list to possibly look into adding an option, where the assemblies would be loaded up into a separate AppDomain instead and the AppDomain immediately removed after the cache information is retrieved. We also could tie up with something like Cecil or Roslyn however those would require external dependencies that we're prefer to not have, so the first option is probably best. I'm not sure of a timeframe on that yet.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.