Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Error: Bad IL format. Please support .NET Core 3.0, 3.1 #112

Closed
CRC32EX opened this issue Oct 14, 2019 · 13 comments
Closed

Error: Bad IL format. Please support .NET Core 3.0, 3.1 #112

CRC32EX opened this issue Oct 14, 2019 · 13 comments

Comments

@CRC32EX
Copy link

CRC32EX commented Oct 14, 2019

Steps to reproduce this issue

1. Write code

// Program.cs
using System;
using ZeroFormatter;

namespace ZeroFormatterTest
{
  [ZeroFormattable]
  public class MyClass
  {
    [Index(0)]
    public virtual int Age { get; set; }
  }

  class Program
  {
    static void Main(string[] args)
    {
      var mc = new MyClass { Age = 1 };
      ZeroFormatterSerializer.Serialize(mc);
    }
  }
}

2. Execute

$ dotnet run
Unhandled exception. System.BadImageFormatException: Bad IL format.
  at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.ZeroFormatterTest.MyClass$Formatter.Serialize(Byte[]& , Int32 , MyClass )
  at ZeroFormatter.ZeroFormatterSerializer.CustomSerializer`1.Serialize[T](Byte[]& buffer, Int32 offset, T obj)
  at ZeroFormatter.ZeroFormatterSerializer.CustomSerializer`1.Serialize[T](T obj)
  at ZeroFormatter.ZeroFormatterSerializer.Serialize[T](T obj)
  at ZeroFormatterTest.Program.Main(String[] args) in C:\Programs\VC\ZeroFormatterTest\ZeroFormatterTest\Program.cs:line 20

Possible solution

  • use .NET Core 2.2, instead of .NET Core 3.0
  • use .NET Core 2.2, instead of .NET Core 3.1

Environment

  • Windows 10 64bit 1903 (Build 18362.30)
  • .NET Core 3.0.100
  • .NET Core 3.1.100
  • ZeroFormatter 1.6.4
  • Visual Studio Community 2019
@btogkas
Copy link

btogkas commented Nov 20, 2019

In order to fix this you will need to change
DynamicFormatter.cs
private static void CreateSerialize(Type elementType, ....formattersInField)

....
// if(segment != null)
...
il.Emit(OpCodes.Call, typeof(IZeroFormatterSegment).GetTypeInfo().GetMethod("Serialize"));

to

il.Emit(OpCodes.Callvirt, typeof(IZeroFormatterSegment).GetTypeInfo().GetMethod("Serialize"));

@enshivam
Copy link

+1

@CRC32EX CRC32EX changed the title Error: Bad IL format. Please support .NET Core 3.0 Error: Bad IL format. Please support .NET Core 3.0, 3.1 Mar 16, 2020
@roikra
Copy link

roikra commented Mar 23, 2020

Any progress regarding this issue? I am also struggling with it.

@btogkas
Copy link

btogkas commented Mar 23, 2020

The solution is above. You have to get the code and On DynamicFormatter.cs
you have to change OpCodes.Call to OpCodes.Callvirt on the line i have posted. Unfortunately i have not the right to pr - merge.

@roikra
Copy link

roikra commented Mar 23, 2020

Can we open a PR?

@roikra
Copy link

roikra commented Mar 23, 2020

CreateSerialize does not exist in CreateSerialize.
Are you referring to the NetCore project?

@truecooler
Copy link

truecooler commented May 5, 2020

CreateSerialize does not exist in CreateSerialize.
Are you referring to the NetCore project?

@roikra
check it out here
works fine with .net core 3

@OvsyannikovAA
Copy link

CreateSerialize does not exist in CreateSerialize.
Are you referring to the NetCore project?

@roikra
check it out here
works fine with .net core 3

This solution doesn't work for me.

@OvsyannikovAA
Copy link

OvsyannikovAA commented May 8, 2020

CreateSerialize does not exist in CreateSerialize.
Are you referring to the NetCore project?

In method:

static TypeInfo BuildFormatter(ModuleBuilder builder, Type resolverType, Type elementType, Tuple<int, EmittableMemberInfo>[] memberInfos)

You must change line:

il.Emit(OpCodes.Call, typeof(IZeroFormatterSegment).GetTypeInfo().GetMethod("Serialize"));

To:

il.Emit(OpCodes.Callvirt, typeof(IZeroFormatterSegment).GetTypeInfo().GetMethod("Serialize"));

@balendra-singh
Copy link

balendra-singh commented Aug 7, 2020

@btogkas The above solution works if the above changes are done on both the projects

  1. ZeroFormatter
  2. ZeroFormatter.NETCore

Cheers!

@CRC32EX
Copy link
Author

CRC32EX commented Feb 28, 2021

This issue was resolved.
Install this package.

Install-Package Alexinea.ZeroFormatter

https://github.com/alexinea/Alexinea.ZeroFormatter/

@CRC32EX CRC32EX closed this as completed Feb 28, 2021
gouske-sbgs added a commit to Gouske-Company/ZeroFormatter that referenced this issue Mar 25, 2021
gouske-sbgs added a commit to Gouske-Company/ZeroFormatter that referenced this issue Mar 25, 2021
xemed-ahope added a commit to xemed/ZeroFormatter that referenced this issue May 7, 2021
Upstream is abandonware: the owner has ignored this one-line fix.

See also `Alexinea.ZeroFormatter` which is actively maintained.
@romeshniriella
Copy link

This issue was resolved.
Install this package.

Install-Package Alexinea.ZeroFormatter

https://github.com/alexinea/Alexinea.ZeroFormatter/

Lifesaver! Thank you.

@perennialmind
Copy link

This issue was resolved.
Install this package.

Install-Package Alexinea.ZeroFormatter

https://github.com/alexinea/Alexinea.ZeroFormatter/

Lifesaver! Thank you.

It looks like that fork changed the wire format of DateTime from (seconds,nanos) to (ticks) - without updating any docs.
master...alexinea:master#diff-e09fd40df61d89d615fe9be86f2da4ed8ec5d79e04e7b57cb0b92265bc838525L581

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants