Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with BadImageFormatException when instantiating generic class referencing ObservableCollection #10

Open
jho1965us opened this issue Jun 10, 2017 · 7 comments

Comments

@jho1965us
Copy link

The following code will reproduce the problem
Using CNeptune version 1.2.1

namespace NConcernConstructorFail
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = new A(); // OK
            var b = new B<int>(); // System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)'
        }
    }
    class A
    {
        ObservableCollection<int> o = new ObservableCollection<int>();
    }
    class B<T>
    {
        ObservableCollection<T> o = new ObservableCollection<T>();
    }
}
@jho1965us
Copy link
Author

jho1965us commented Jun 10, 2017

Actually not related to ObservableCollection<T> also happens with List<T>

@Puresharper
Copy link
Owner

Puresharper commented Jun 12, 2017

Interesting, thank you for report.
I will try it as soon as possible.

@jho1965us
Copy link
Author

jho1965us commented Jun 12, 2017

FWIW: I tryed decompile with ILSpy, after fixing a null reference error in ILSpy I got the following for B

internal class B<T>
{
	[CompilerGenerated, Serializable]
	internal static class <Neptune>
	{
		[CompilerGenerated, Serializable]
		public static class <Authentic>
		{
			public static void <Constructor>(B @this) // Should be B<T> not B (probably not ILSpy issue, manual written similar code decompile ok)
			{
				@this.o = new List<!0>(); // Should be T not !0 (probably not ILSpy issue, manual written similar code decompile ok)
				@this..ctor(); // OK, ILSpy is confused code: actually @object..ctor(@this);
			}
		}

		[CompilerGenerated, Serializable]
		public static class <Intermediate>
		{
			[CompilerGenerated, Serializable]
			public static class <<Constructor>>
			{
				[DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
				public static IntPtr <Pointer> = MethodBase.GetMethodFromHandle(methodof(B.<Neptune>.<Authentic>.<Constructor>(B)).MethodHandle, typeof(B.<Neptune>.<Authentic>).TypeHandle).MethodHandle.GetFunctionPointer(); // not sure probably should have been B<T>
			}
		}
	}

	private List<T> o;

	public B()
	{
		calli(System.Void(NConcernConstructorFail.B`1), this, B.<Neptune>.<Intermediate>.<<Constructor>>.<Pointer>); // not sure probably should have been B<T>
	}

@hoxcape
Copy link

hoxcape commented Aug 25, 2017

I found a hint,the generated delegates lost generic type constraints.
I'm trying on it

@akovac35
Copy link

Same error - was this fixed?

@asheeshb
Copy link

This issue is still there. For checking if the issue was with Mono.Cecil, I upgraded Mono.Cecil to 10.0 and changed some breaking code within CNeptune. But it did not help resolve this issue.

@jho1965us
Copy link
Author

I fixed it on my branches and made a pull request however Virtuoze has not taken the pull request. You can download the source from my branches https://github.com/jho1965us/CNeptune and https://github.com/jho1965us/NConcern but you will have to build it your self. Also the code that modifies the project file to run NConcern is not on github so you will have to modify the project file manually (Hint install the official version first then modify the project to the CNeptune.exe you build your self). More details in the the pull request comment #17

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

No branches or pull requests

5 participants