Search code examples
c#macosxamarincodedomxamarin.mac

C# CodeDom System.TypeLoadException XamMac2 Xamarin macOS


I'm coding a complex application that makes use of CodeDom to instantiate objects with reflection. It is, however, mixed between netstandard2.0 (the wrapper in between that also supports net461) and net461 projects.

As I've read, it is very possible to make reference to previous versions of the framework, this case the following:

{System.TypeLoadException: Could not resolve type with token 01000067 from typeref (expected class 'System.CodeDom.Compiler.CompilerParameters' in assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')  

Disregarding the System reference that gets loaded in memory for the Xamarin Mac executable.

What doesn't fit is the code looking for the a System assembly that maybe gets overwritten with the Xamarin System assembly.

Do you know any workaround for this? Other than migrating entirely the remaining set of projects to hybrid between netstandard2.0 and net461.

Thanks.


Solution

  • Indeed.

    There was a mismatch between the System.CodeDom assembly that is packed inside System.dll and the one that must be referenced for the project to build.

    This got solved by targeting netstandard2.0 with both net461 set.

      <PropertyGroup>
        <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
      </PropertyGroup>
    

    Like so.