“The located assembly's manifest definition does not match the assembly reference” when assembly is renamed

StackOverflow https://stackoverflow.com/questions/12384979

  •  01-07-2021
  •  | 
  •  

Question

I have an MyApp.exe.config that contains this:

<section name="keys" type="MyApp.KeysSection, MyApp" />

This works as expected. However, when I rename MyApp.exe to MyApp.renamed.exe, and the config file to MyApp.renamed.exe.config, I get an exception : "Could not load file or assembly 'MyApp' or one of its dependencies. The system cannot find the file specified".

Ok, so this must be because the config file is still referencing the MyApp assembly. So I updated it to read :

<section name="keys" type="MyApp.KeysSection, MyApp.renamed" />

When I run the application, I then get a new exception: "The located assembly's manifest definition does not match the assembly reference".

I understand what the above message means, but doesn't this mean that I'm unable to rename my assembly without also generating a new manifest file? Ideally, I'd like to be able to rename my assembly, and have it still work. The reason for this is because the app has various "flavours" and I wanted to use file names such as MyApp.Flavour1.exe, MyApp.Flavour2.exe etc but this won't work without generating different manifests and configuration files for each flavour, as it is.

What I'm asking, is whether there's a way to create my assembly such that renaming the file doesn't cause it to throw this exception.

Was it helpful?

Solution

Unfortunately, you cannot rename an assembly in this way. See Loading renamed C# assembly throws FileNotFoundException for more information.

Instead, you may want to create different projects that contain the same or similar files or move common files to a separate assembly and have the different "flavor" assemblies reference the common assembly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top