Unable to use System.Web.dll from a Xamarin Mac application

danipendanipen USMember ✭✭

Hi, we recently updated our Mac application to use the Unified API. We're targeting the Xamarin.Mac .NET 4.5 Framework.

Some of our assemblies uses System.Web.dll. When the application tries to use a class inside System.Web.dll, I get the following exception.

System.BadImageFormatException: Method has zero rva
  at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/3508/cbea5f86/source/xamarin-macios/src/AppKit/NSApplication.cs:94
  at ScrollBarExample.MainClass.Main (System.String[] args) [0x00007] in /Users/daniel/Projects/NewXamMac/ScrollBarExample/Main.cs:10

Is there any workaround for this issue? Thanks!

Best Answer


  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    $ ls /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/System.Web.*.dll

    $ ls /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/System.Web.*.dll

    System.Web.dll is not part of the supported target frameworks. I'm rather curious how it even was resolved at runtime (did you copy assemblies in from system mono?).

    I would suggest reworking your application to not require System.Web, or moving to the unsupported System Mono target framework if that is impossible (and letting me know what functionality you need from System.Web, much of it is WCF sever side stuff that is not something we considered supported).

  • danipendanipen USMember ✭✭

    Unfortunately we cannot move to the unsupported System Mono target framework, because we found a bug that causes that when we apply magnification to a NSView, then when we move the scroll the view is not correctly drawn.

    I'm using all the Encode and Decode stuff from HttpUtility from System.Web.dll. Is there any way to use that stuff without referencing the System.Web.dll assembly?

  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Sounds like you just need this one file:


    It looks like we pull that into System.Web.Services.dll, so try referencing that assembly instead.

  • danipendanipen USMember ✭✭
    edited December 2016

    In our case is not that easy unfortunately. Some of our assemblies that uses System.Web.dll are shared between Windows, Linux and Mac, and they're referencing .NET 2.0 target framework. I think that the best solution is this case is including the HttpUtility stuff in our code. What do you think?

    ADDITIONALLY: How can I specify the mmp packager to use UseXamMacFullFramework?


  • ChrisHamonsChrisHamons USXamarin Team Xamurai

    Yeah, if you can't add a reference then pulling in the HttpUtility to your code (maybe conditionally on Mac only?) seems reasonable. Much better than adding a full reference to an unsupported lib for a few functions.

    On your second question, the current solution is a hack:


    I've fixed it in master, but right now mmp determines it based upon the Xamairn.Mac assembly you reference. So if you reference /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Xamarin.Mac.dll you'll get full (XM 4.5). I added a specific flag in master.

  • danipendanipen USMember ✭✭

    Sorry Chris, I changed my references in my NAnt script to use the following Xamarin.Mac.dll assembly, but the bug is still there (when I compile using Xamarin Studio it works fine).

    <exec program="/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp" workingdir="${clientdir}../../../" failonerror="true">
        <arg line="-nolink -sgen -minos=10.6 --arch=i386 --sdkroot /Applications/Xcode.app/Contents/Developer" />
        <arg line="-o ${clientbinpath} -n macplastic --profile 4.5" />
        <arg line="-a /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Xamarin.Mac.dll " />

    How could I check/ensure that the Xamarin.Mac 4.5 runtime is being by my package?

Sign In or Register to comment.