Skip to content

TypeLoadException on mono 4.2.1 #424

Closed

Description

@sklose

I am getting this exception when I try to use Dapper on mono

System.TypeInitializationException: The type initializer for 'Dapper.SqlMapper' threw an exception. 
---> System.TypeLoadException: Failed for unknown reasons.

Looking at the type initializer code of SqlMapper and the mono documentation, it seems that

AddTypeHandlerImpl(typeof(IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord>), new SqlDataRecordHandler(), false);

is the culprit - Microsoft.SqlServer.Server.SqlDataRecord is listed nowhere in the mono docs, I guess it isn't implemented.

Activity

  1. mgravell commented on Dec 18, 2015

    @mgravell
    Member

    K, that's fun. I will see if we can wrap that in some hackery to dodge
    around that. Should have something in the next few days.
    On 18 Dec 2015 23:20, "Sebastian Klose" [email protected] wrote:

    I am getting this exception when I try to use Dapper on mono

    System.TypeInitializationException: The type initializer for 'Dapper.SqlMapper' threw an exception.
    ---> System.TypeLoadException: Failed for unknown reasons.

    Looking at the type initializer code of SqlMapper and the mono
    documentation, it seems that

    AddTypeHandlerImpl(typeof(IEnumerable<Microsoft.SqlServer.Server.SqlDataRecord>), new SqlDataRecordHandler(), false);

    is the culprit - Microsoft.SqlServer.Server.SqlDataRecord is listed
    nowhere in the mono docs, I guess it isn't implemented.

    —
    Reply to this email directly or view it on GitHub
    #424.

  2. mgravell commented on Dec 19, 2015

    @mgravell
    Member

    Please can I ask you to verify via 1.50.0-beta6 (available on nuget)?

  3. sklose commented on Dec 19, 2015

    @sklose
    Author

    It's working for me, thanks for the quick fix!

  4. mgravell commented on Dec 19, 2015

    @mgravell
    Member

    @sklose thanks for a clear bug report that let me understand exactly what the problem was and what needed changing ;p (sadly, they're not always so clear)

  5. NilufarMakhmudova commented on Aug 3, 2018

    @NilufarMakhmudova

    @mgravell, we are experiencing a similar problem with our Xamarin Android solution with SQLite database, where Dapper 1.50.5 NuGet package is installed.
    System.TypeInitializationException: The type initializer for 'Dapper.SqlMapper' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Dapper.SqlMapper.AddTypeHandlerImpl (System.Type type, Dapper.SqlMapper+ITypeHandler handler, System.Boolean clone)
    at Dapper.SqlMapper.ResetTypeHandlers (System.Boolean clone)
    at Dapper.SqlMapper..cctor ()

    Are there any clues on how to fix it?

  6. added a commit that references this issue on Feb 8, 2026
    9264472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions