|
70 | 70 | - You are trying to load an unmanaged dynamic link library or executable (such as a Windows system DLL) as if it were a .NET assembly. The following example illustrates this by using the <xref:System.Reflection.Assembly.LoadFile%2A?displayProperty=nameWithType> method to load Kernel32.dll. |
71 | 71 |
|
72 | 72 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.badimageformatexception.class/cs/condition1.cs" id="Snippet1"::: |
| 73 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.badimageformatexception.class/fs/condition1.fs" id="Snippet1"::: |
73 | 74 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.badimageformatexception.class/vb/condition1.vb" id="Snippet1"::: |
74 | 75 |
|
75 | | - To address this exception, access the methods defined in the DLL by using the features provided by your development language, such as the `Declare` statement in Visual Basic or the <xref:System.Runtime.InteropServices.DllImportAttribute> attribute with the `extern` keyword in C#. |
| 76 | + To address this exception, access the methods defined in the DLL by using the features provided by your development language, such as the `Declare` statement in Visual Basic or the <xref:System.Runtime.InteropServices.DllImportAttribute> attribute with the `extern` keyword in C# and F#. |
76 | 77 |
|
77 | 78 | - You are trying to load a reference assembly in a context other than the reflection-only context. You can address this issue in either of two ways: |
78 | 79 |
|
|
86 | 87 | - Your application's components were created using different versions of .NET. Typically, this exception occurs when an application or component that was developed using the .NET Framework 1.0 or the .NET Framework 1.1 tries to load an assembly that was developed using the .NET Framework 2.0 SP1 or later, or when an application that was developed using the .NET Framework 2.0 SP1 or .NET Framework 3.5 tries to load an assembly that was developed using the .NET Framework 4 or later. The <xref:System.BadImageFormatException> may be reported as a compile-time error, or the exception may be thrown at run time. The following example defines a `StringLib` class that has a single member, `ToProperCase`, and that resides in an assembly named StringLib.dll. |
87 | 88 |
|
88 | 89 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.badimageformatexception.class/cs/stringlib.cs" id="Snippet2"::: |
| 90 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.badimageformatexception.class/fs/stringlib.fs" id="Snippet2"::: |
89 | 91 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.badimageformatexception.class/vb/stringlib.vb" id="Snippet2"::: |
90 | 92 |
|
91 | 93 | The following example uses reflection to load an assembly named StringLib.dll. If the source code is compiled with a .NET Framework 1.1 compiler, a <xref:System.BadImageFormatException> is thrown by the <xref:System.Reflection.Assembly.LoadFrom%2A?displayProperty=nameWithType> method. |
92 | 94 |
|
93 | 95 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.badimageformatexception.class/cs/loadstringlib.cs" id="Snippet3"::: |
| 96 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.badimageformatexception.class/fs/loadstringlib.fs" id="Snippet3"::: |
94 | 97 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.badimageformatexception.class/vb/loadstringlib.vb" id="Snippet3"::: |
95 | 98 |
|
96 | 99 | To address this exception, make sure that the assembly whose code is executing and that throws the exception, and the assembly to be loaded, both target compatible versions of .NET. |
97 | 100 |
|
98 | 101 | - The components of your application target different platforms. For example, you are trying to load ARM assemblies in an x86 application. You can use the following command-line utility to determine the target platforms of individual .NET assemblies. The list of files should be provided as a space-delimited list at the command line. |
99 | 102 |
|
100 | 103 | :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.badimageformatexception.class/cs/targetplatform1.cs" id="Snippet4"::: |
| 104 | + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.badimageformatexception.class/fs/targetplatform1.fs" id="Snippet4"::: |
101 | 105 | :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.badimageformatexception.class/vb/targetplatform1.vb" id="Snippet4"::: |
102 | 106 |
|
103 | 107 | - Reflecting on C++ executable files may throw this exception. This is most likely caused by the C++ compiler stripping the relocation addresses or the .Reloc section from the executable file. To preserve the .relocation address in a C++ executable file, specify /fixed:no when linking. |
|
0 commit comments