Search code examples
c#64-bitroslynanalyzerbuildconfiguration

Are x64 build configurations supported for Roslyn Analyzers?


I'd like to add an analyzer to a solution that exclusively contains x64 projects, and the analyzer is only meant to be applied to projects of that solution. Can I have a x64 build configuration for my Analyzer?

If I try that, the Analyzer compiles with x64, but when I try to add the Analyzer to a x64 project, I get IntelliSense warning CS8034 of category Roslyn.HostError:

Unable to load Analyzer assembly C:...\TestAnalyzer.dll: Could not load file or assembly 'file:///C:\Users...\TestAnalyzer.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Adding the same analyzer when it is compiled with x86 works fine.


Solution

  • Roslyn doesn't care about the bitness of your analyzers; it just loads .Net assemblies.

    However, Visual Studio itself is an x86 process.

    If you make an x64-only analyzer, it will run perfectly fine from the Roslyn command line, but VS won't be able to load it.


    Note that analyzer bitness has nothing to do with project bitness; analyzers are loaded into the compiler, not at runtime.