System.ApplicationException in AddExternalReference

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 17 years ago by Edward
Version: 4.0.0246
Environment: Windows XP (32-bit)
Avatar
Hi,

We are currently experiencing an issue when calling DotNetProjectResolver.AddExternalReference on an assembly that contains structures marked with
[System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
and
[MarshalAs(UnmanagedType.ByValArray, SizeConst=15)]
public byte[] password;
I get this exception:
System.ApplicationException: Could not load exported type data for assembly
'Sample, Version=1.0.2638.32928, Culture=neutral, PublicKeyToken=null'. --->
System.TypeLoadException: Could not load type PSAuthT from assembly Sample,
Version=1.0.2638.32928, Culture=neutral, PublicKeyToken=null because it contains an
object field at offset 0 that is incorrectly aligned or overlapped by a non-object
field.
When we load the dll with the Quick Start we get the same exception.
This issue could be due to reflection on the dll but we found that .Net reflector is well able to disassemble this library.

Finding a workaround or fixing this would be of great help for us.
We are supposed to deliver a project based on SyntaxEditor referencing such kind of assemblies.

I'll send you by email the failing assembly.

Thanks a lot in advance for your help,
Regards,

Edward.

[Modified at 03/23/2007 12:36 PM]

Comments (6)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Edward,

Thanks for the sample DLL. This is only happening in .NET 1.1. Upon our call to Assembly.GetExportedTypes, Microsoft's internal code is throwing an exception:

{ "Could not load type PSDnsAddrT from assembly CpaCS, Version=1.0.2638.31823, Culture=neutral, PublicKeyToken=null because the format is invalid." }

I can duplicate this in two lines of code:
System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(@"C:\sample.dll");
a.GetExportedTypes();
So it appears that .NET is unable to load the types for the assembly properly. Since we rely on .NET being able to load it, unfortunately I'm not sure what we can do in this scenario. Any ideas why that exception is occurring?


Actipro Software Support

Posted 17 years ago by Edward
Avatar
Thank you for your quick answer.

That's right, I tried with your Open C# Sample Project (for .NET 2.0 and later) and it works fine.

So I think we cannot do anything about this exception thrown by the framework 1.1, so we can allow code completion to be disabled on such assemblies.

Nevertheless it seems like the component crashes when this exception occurs: even when I catch the exception the syntax coloration is completely down, and the code completion is down for all the assemblies of the resolver.

Any chance you catch this exception on your side since it must be quite at a low level in your design? This would prevent the resolver to fail on other assemblies.

Thanks and Regards,


Edward
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm having trouble duplicating this. I inserted some code in our code where GetExportedTypes is called to throw an exception if an assembly of a certain name was loaded. Then I ran the .NET Reflection QuickStart and loaded an assembly with that name. An exception was thrown, I saw a messagebox (that is in the top-level catch) and was able to continue fine.

Could you package together a tiny sample project that shows the problem you are having since I'm unable to duplicate it? Please use .NET 2.0 if possible. Thanks.


Actipro Software Support

Posted 17 years ago by Edward
Avatar
Sorry, I found that the problem with loosing the code completion and the syntax color was my mistake.

As long as we will stay on .Net 1.1 we will have the code completion unavailable on such assemblies, we will use .Net 2.0 as soon as possible.

Thanks to the support team,

Edward
Posted 17 years ago by Edward
Avatar
Hi,

We're currently working on a migration to C# 2.0 and again we get the same TypeLoadException in the Quick Start.
We're trying to find out how to change our assembly to make it able to be reflected by your component. It seems that Visual Studio and SharpDevelop have no problem with reflecting it, how could we find a quick work around?

I send you a sample assembly with its C# source code.

The assembly is compiled in .Net 2.0, and we are using the SyntaxEditor with the Language Addon C# 2.0.

Kind regards,

Edward

[Modified at 04/03/2007 09:18 AM]
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Edward,

I can duplicate this with a couple lines of regular .NET code.

Try this in any .NET project:
System.Reflection.Assembly a = System.Reflection.Assembly.LoadFrom(pathToAssembly);
Type[] types = a.GetExportedTypes();
When I do that, I get this exception:
Could not load type 'd' from assembly 'Cpt.Wrappers, Version=2.0.2649.24017, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.

If you can resolve why that is happening then our stuff should load it fine. Any ideas?

I bet if you take that exception and search google you can find what you need to change in your code to make it work.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.