The type 'XmlElement' is defined in an assembly that is not referenced. You must add a reference to

KeithBoyntonKeithBoynton Keith BoyntonGBMember ✭✭

I have the following code in a library project that is referenced within a Xamarin.Mac Modern targeted project.

GlobalContext.Properties["LoggingPath"] = Path.Combine(ConfigurationHelper.sConfigurationPath, "logs");
log4net.Config.XmlConfigurator.Configure(new FileInfo(file));

The main project which generates an executable references System.Xml version 2.0.5.0 from the Xamarin.Mac package.

The following error occurs during build:

The type 'XmlElement' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

It could be interesting to note that I have a Xamarin.iOS project that uses the same set up obviously targeting Xamarin.iOS instead and that is working. I've not yet found what it is that's different other than the implementation of System.Xml.

Posts

  • TimothyRisiTimothyRisi Timothy Risi USXamarin Team Xamurai

    Hi Keith,

    Are you able to create a basic project that reproduces the error? Are you using a Xamarin.Mac Class Library project, a PCL library, a Shared Library, or a .NET Standard Library? Are you using any nuget packages in the library or XM project that might be referencing System.Xml?

  • KeithBoyntonKeithBoynton Keith Boynton GBMember ✭✭

    Hi @TimothyRisi thanks for the really quick reply!

    I have created a basic project that reproduces the error, hopefully that illustrates the issue properly. I've added the code to the Main class file.

    The project is attached.

    Thank you for your help.

  • TimothyRisiTimothyRisi Timothy Risi USXamarin Team Xamurai

    Is log4net a library of yours, or from a third-party package? The error appears to be coming from that library.

  • KeithBoyntonKeithBoynton Keith Boynton GBMember ✭✭

    Hi Timothy,

    It's a port from Apache of the Log4J library, a pretty well known logging framework.

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    So the log4net assembly roughly appears to be depending on Modern libraries, which is what you'd expect to user it in a modern XM app:

    $ monop --refs -r:~/Downloads/XmlElementDemo/XmlElementDemo/Resources/log4net.dll 
    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    
     $ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/mscorlib.dll  | head
    
    Assembly Information:
    mscorlib
    Version=4.0.0.0
    Culture=neutral
    PublicKeyToken=b77a5c561934e089
    

    The problem the System.xml.dll library it depends on does not match what XM ships:

        $ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/Xamarin.Mac/System.Xml.dll | head
    
    Assembly Information:
    System.Xml
    Version=2.0.5.0
    Culture=neutral
    PublicKeyToken=7cec85d7bea7798e
    

    7cec85d7bea7798e != b77a5c561934e089

    What Tim was asking was roughly "Is this assembly specifically built to build against Xamarin.Mac Modern?" or did you take a build for Xamarin.iOS and try to use it?

  • ChrisHamonsChrisHamons Chris Hamons USXamarin Team Xamurai

    A bit more research suggests the assembly in question is built against desktop System.Xml.dll

     $ monop -r:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/System.Xml.dll | head
    
    Assembly Information:
    System.Xml
    Version=4.0.0.0
    Culture=neutral
    PublicKeyToken=b77a5c561934e089
    

    And swapping your target framework (https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/) to Full makes it compile.

    So you either need to use that target framework to consume this library, or get it recompiled against the Modern BCL.

Sign In or Register to comment.