Reputation: 10191
I have a method which checks the version of an assembly and if it's out of date overrides it. To detect the version I'm using the following code:
version = Type.GetType(typeName).Assembly.GetName().Version;
However, if I deem that this version is out of date when I try and override it I get the following error
The process cannot access the file... because it is being used by another process.
It seems to me that the act of reflecting the assembly is causing it to load into the program and so it can't be overridden.
How can I either
Upvotes: 3
Views: 1366
Reputation: 392833
Consider using Mono.Cecil
which is a superior (well, pre-Roslyn) CIL assembly reader/writer.
Upvotes: 0
Reputation: 551
Load the copy of your assembly in the following way.
var assembly = Assembly.Load(File.ReadAllBytes("YourAssembly.dll"));
You can now override the assembly that's on your disk.
Upvotes: 2