Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mkbundle Mono Assembly binding redirection

I have a sample .NET application that runs fine on windows, and my Ubuntu environment using mono.

I am trying to use Mkbundle to create a single native assembly so I can docker containerize it using busybox and keep the size small instead of the usually huge bloated containers.

The problem I am running into is with Json.net, I think its due to assembly binding redirection from the app.config file, anyone else ran into this?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /></startup>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

And its producing the following error both with and without --static

enter image description here

like image 510
user1689716 Avatar asked Jan 08 '23 04:01

user1689716


1 Answers

How I got around it was to specify the --nodeps flag.

mkbundle --nodeps -o console OutsideSourcesAPI.exe *.dll

However, when you run it, it may give you errors like...

The assembly mscorlib.dll was not found or could not be loaded.

or

Unhandled Exception: System.IO.FileNotFoundException: 
Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies.

You'll then have to specify any missing dependencies manually (I know, kinda of stinks)

mkbundle --nodeps -o console OutsideSourcesAPI.exe *.dll mscorlib.dll System.Xml.dll
like image 191
Jimmy_Byrd Avatar answered Jan 10 '23 17:01

Jimmy_Byrd