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

TypeLoadException due to BLOCK_REGION_UNION #55

Closed
alexrp opened this issue Jun 6, 2019 · 5 comments
Closed

TypeLoadException due to BLOCK_REGION_UNION #55

alexrp opened this issue Jun 6, 2019 · 5 comments
Assignees
Labels
Projects

Comments

@alexrp
Copy link

alexrp commented Jun 6, 2019

Describe the bug

System.TypeLoadException
  HResult=0x80131522
  Message=Could not load type 'BLOCK_REGION_UNION' from assembly 'Vanara.PInvoke.Kernel32, Version=2.3.10.0, Culture=neutral, PublicKeyToken=c37e4080322237fa' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.

What code is involved
No code, simply referencing several of the Vanara assemblies seems to trigger it. Not exactly sure which, but my project is referencing these:

  • Vanara.PInvoke.Mpr
  • Vanara.PInvoke.NtDll
  • Vanara.PInvoke.Shell32
  • Vanara.PInvoke.User32
  • Vanara.PInvoke.User32.Gdi
  • Vanara.PInvoke.WinINet

(And all dependencies of these.)

Expected behavior
No TLE.

@alexrp
Copy link
Author

alexrp commented Jun 6, 2019

Hm. The reason it shows up is probably because I'm using MEF in this project, which scans over all referenced assemblies and their types, forcing them to be loaded.

@alexrp
Copy link
Author

alexrp commented Jun 6, 2019

Happens both with 2.3.9 and 2.3.10.

@dahall dahall closed this as completed in eaa0dd7 Jun 6, 2019
@dahall
Copy link
Owner

dahall commented Jun 6, 2019

I applied and posted a fix just now that should resolve this issue. If you can build, please test. Otherwise, I'll include in my next release.

@dahall dahall reopened this Jun 6, 2019
@dahall dahall self-assigned this Jun 6, 2019
@dahall dahall added the bug label Jun 6, 2019
@dahall dahall added this to To do in PInvoke via automation Jun 6, 2019
@alexrp
Copy link
Author

alexrp commented Jun 6, 2019

I think a simple test case would be something along these lines:

using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;

class Program
{
    static void Main()
    {
        foreach (var file in Directory.EnumerateFiles(".", "Vanara*.dll"))
            foreach (var type in Assembly.LoadFrom(file).DefinedTypes)
                RuntimeHelpers.RunClassConstructor(type.TypeHandle);
    }
}

Place all the Vanara assemblies next to this program and it'll load all of them and force all types (nested or otherwise) in them to be initialized, which will result in exception(s) if any of them have invalid layout.

@dahall
Copy link
Owner

dahall commented Jun 9, 2019

Fixed and released today in 2.3.11

@dahall dahall closed this as completed Jun 9, 2019
PInvoke automation moved this from To do to Done Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
PInvoke
  
Done
Development

No branches or pull requests

2 participants