locked
Need help with System.BadImageFormatException...The module was expected to contain an assembly manifest

    Question

  • I'm working on a very large Visual Basic system. It contains many DLLs and EXEs that use Interop to move between VB6 COM components and VB.NET 2003 components. We recently started upgrading the VB.NET 2003 portions of the system to VB.NET 2005 and are now getting an unexpected error during compilation.

     

    The error message seems to indicate that an assembly is missing a manifest. The problem is that the indicated file is not a .NET assembly. It is a VB6 dll. The indicated file is also not directly referenced from the project that we are attempting to compile. It is referenced from another DLL that is also a VB6 DLL. My best guess as to what is going on (purely conjecture) is that the compiler has become confused about what type of component is being loaded and is trying to enforce the rules for a .NET component on a COM component.

     

    A bit more info on how we are making our references...

     

    For .NET dlls, we run "REGASM /codebase xxx.dll /tlb:Relius.Admin.xxx.tlb" to create TLBs that we reference from VB6.

    For COM dlls, we run "TLBIMP xxx.dll /OUT:Relius.Admin.xxx.dll /Namespace:Relius.Admin.xxx /asmversion:13.0.0.0" to create a RCW and then reference the Relius.Admin.xxx.dll from our DOTNET projects.

     

    These procedures have worked in the past with VB.NET 2003 but it seems that VB.NET 2005 is having problems with this approach.

     

    The error message follows:

     

    Error 1 The "ResolveAssemblyReference" task failed unexpectedly.
    System.BadImageFormatException: Could not load file or assembly 'C:\Relius\Admin\V13.0\QTSQLMap.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
    File name: 'C:\Relius\Admin\V13.0\QTSQLMap.dll'
       at System.Reflection.AssemblyName.nGetFileInformation(String s)
       at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
       at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path)
       at Microsoft.Build.Tasks.SystemState.GetAssemblyName(String path)
       at Microsoft.Build.Tasks.Resolver.FileMatchesAssemblyName(AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, Boolean allowMismatchBetweenFusionNameAndFileName, String pathToCandidateAssembly, ResolutionSearchLocation searchLocation)
       at Microsoft.Build.Tasks.Resolver.ResolveAsFile(String fullPath, AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, Boolean allowMismatchBetweenFusionNameAndFileName, ArrayList assembliesConsideredAndRejected)
       at Microsoft.Build.Tasks.Resolver.ResolveFromDirectory(AssemblyNameExtension assemblyName, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String directory, ArrayList assembliesConsideredAndRejected)
       at Microsoft.Build.Tasks.DirectoryResolver.Resolve(AssemblyNameExtension assemblyName, String rawFileNameCandidate, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String hintPath, String assemblyFolderKey, ArrayList assembliesConsideredAndRejected, String& foundPath, Boolean& userRequestedSpecificFile)
       at Microsoft.Build.Tasks.AssemblyResolution.ResolveReference(IEnumerable`1 jaggedResolvers, AssemblyNameExtension assemblyName, String rawFileNameCandidate, Boolean isPrimaryProjectReference, Boolean wantSpecificVersion, String[] executableExtensions, String hintPath, String assemblyFolderKey, ArrayList assembliesConsideredAndRejected, String& resolvedSearchPath, Boolean& userRequestedSpecificFile)
       at Microsoft.Build.Tasks.ReferenceTable.ResolveReference(AssemblyNameExtension assemblyName, String rawFileNameCandidate, Reference reference)
       at Microsoft.Build.Tasks.ReferenceTable.ResolveAssemblyFilenames()
       at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure()
       at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetRegistrySubKeyNames getRegistrySubKeyNames, GetRegistrySubKeyDefaultValue getRegistrySubKeyDefaultValue, GetLastWriteTime getLastWriteTime)
       at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute()
       at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)

    Assembly manager loaded from:  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
    Running under executable  C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe
    --- A detailed error log follows.

    === Pre-bind state information ===
    LOG: User = CORBEL\kenb
    LOG: Where-ref bind. Location = C:\Relius\Admin\V13.0\QTSQLMap.dll
    LOG: Appbase = file:///C:/Program Files/Microsoft Visual Studio 8/Common7/IDE/
    LOG: Initial PrivatePath = NULL
    Calling assembly : (Unknown).
    ===
    LOG: This is an inspection only bind.
    LOG: Using application configuration file: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe.Config
    LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Relius/Admin/V13.0/QTSQLMap.dll.
    ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.
     Relius.Admin.Bus.Cafeteria

     

     

     

    Wednesday, September 05, 2007 6:58 PM

All replies

  • Hi,

     

    According to your exception and error message on upgrading this large VB.NET application, I would like to provide you the suggestions as follows:

     

    1. BadImageFormatException exception is thrown when the file image of a DLL or an executable program is invalid. Please make sure you have registered the related DLLs on your current system. You can use RegSvr32 DllName.dll to register the component, then add the reference for your component in Visual Basic 2005 application.

     

    2. "The module was expected to contain an assembly manifest". This is likely to happen if you open an existing manifest that has a reference to a file/assembly and the reference now no longer exists. You can try to add this kind of assemblies again in your upgraded VB 2005 application.

     

    Hope that can provide you some idea and good luck with the upgrading.

    Monday, September 10, 2007 8:14 AM
  • Unfortunately, I had already done both of your suggestions before I created the post. I'm in the process of building the entire application from the ground up so the indicated file definitely exists and was definitely registered. I even went so far as to scan the registry with REGEDIT to ensure this. I also attempted to remove and re-add references to the DLLs in the problematic project. All of this was to no avail.

     

    As I mentioned in my post, I've been building this same system using Visual Studio 2003 with the same techniques for about 3 years now. The problems seem to relate to Visual Studio 2005. There is something that is being handled differently when compiling with Visual Studio 2005. 

    Monday, September 10, 2007 11:52 AM
  • Ken Beccard,

     

    Thanks for your reply. Based on your post, could you please provide the specific information in order to make your problem more clear with the three aspects below:

     

    1. Are you building the project within Visual Studio by using the “Build” or “Rebuild” menu item?

     

    2. What is “Relius.Admin.Bus.Cafeteria”? Is it an COM Interop assembly generated by “tlbimp” command?

     

    3. Could you paste out the content of the project file (e.g. . vbproj) file, especially the part that contains “ResolveAssemblyReference”?

     

    Thanks again for your question and waiting for the reply.

     

    Thursday, September 13, 2007 6:17 AM
  • Thanks for your reply.

     

    To answer your questsions, first let me say that I've gotten past the original example by rearranging some code and removing a reference. I am still getting the same problem in three other projects, however and have found no work arounds for those projects. I will give you information that pertains one of the locations where I am currently experiencing the problem. I have a copy of a "Diagnostic" MSBuild output on the project below but was unable to show it here due to size constrainst on a post to the forum. This particular error refers to QTAutask which isn't directly referenced by the project that is giving the error. QTAutask is being referenced by multiple COM components that are referenced by this project, however.

     

    The following items match up to the points in your response:

     

    1. I am currently building using Visual Studio 2005 SP1 for the DOTNET components and Visual Studio 6 SP6 for the COM components. I have also attempted to use MSBUILD on the DOTNET component and received the same results.

     

    2. We have a naming convention that would indicate the type of file being discussed. Our COM components all start with "QT" and their corresponding RCW (generated with TLBIMP) would be "Relius.Admin.QT...". Our DOTNET programs all begin with "Relius.Admin" and if it isn't a "Relius.Admin.QT..." file, it will be a DLL created with Visual Studio 2005. More to the point, "Relius.Admin.Bus.Cafeteria" is a DOTNET DLL.

     

    3. One of the projects we're currently experiencing difficulty with is Relius.Admin.Bus.OmniImport and the following is a paste of it's project file.

     

    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <ProjectType>Local</ProjectType>
        <ProductVersion>8.0.50727</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>{87814D91-3FE0-4F2D-943F-079F99811D66}</ProjectGuid>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ApplicationIcon>
        </ApplicationIcon>
        <AssemblyKeyContainerName>
        </AssemblyKeyContainerName>
        <AssemblyName>Relius.Admin.Bus.OmniImport</AssemblyName>
        <AssemblyOriginatorKeyFile>
        </AssemblyOriginatorKeyFile>
        <AssemblyOriginatorKeyMode>None</AssemblyOriginatorKeyMode>
        <DefaultClientScript>JScript</DefaultClientScript>
        <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
        <DefaultTargetSchema>IE50</DefaultTargetSchema>
        <DelaySign>false</DelaySign>
        <OutputType>Library</OutputType>
        <OptionCompare>Binary</OptionCompare>
        <OptionExplicit>On</OptionExplicit>
        <OptionStrict>On</OptionStrict>
        <RootNamespace>Relius.Admin.Bus.OmniImport</RootNamespace>
        <StartupObject>
        </StartupObject>
        <FileUpgradeFlags>
        </FileUpgradeFlags>
        <MyType>Windows</MyType>
        <UpgradeBackupLocation>
        </UpgradeBackupLocation>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <OutputPath>bin\</OutputPath>
        <DocumentationFile>Relius.Admin.Bus.OmniImport.xml</DocumentationFile>
        <BaseAddress>285212672</BaseAddress>
        <ConfigurationOverrideFile>
        </ConfigurationOverrideFile>
        <DefineConstants>
        </DefineConstants>
        <DefineDebug>true</DefineDebug>
        <DefineTrace>true</DefineTrace>
        <DebugSymbols>true</DebugSymbols>
        <Optimize>false</Optimize>
        <RegisterForComInterop>false</RegisterForComInterop>
        <RemoveIntegerChecks>false</RemoveIntegerChecks>
        <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
        <WarningLevel>1</WarningLevel>
        <NoWarn>42016,42017,42018,42019,42032</NoWarn>
        <DebugType>full</DebugType>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <OutputPath>bin\</OutputPath>
        <DocumentationFile>Relius.Admin.Bus.OmniImport.xml</DocumentationFile>
        <BaseAddress>285212672</BaseAddress>
        <ConfigurationOverrideFile>
        </ConfigurationOverrideFile>
        <DefineConstants>
        </DefineConstants>
        <DefineDebug>false</DefineDebug>
        <DefineTrace>true</DefineTrace>
        <DebugSymbols>false</DebugSymbols>
        <Optimize>true</Optimize>
        <RegisterForComInterop>false</RegisterForComInterop>
        <RemoveIntegerChecks>false</RemoveIntegerChecks>
        <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
        <WarningLevel>1</WarningLevel>
        <NoWarn>42016,42017,42018,42019,42032</NoWarn>
        <DebugType>none</DebugType>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="ADODB, Version=2.8.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Relius\Admin\V13.0\ADODB.dll</HintPath>
        </Reference>
        <Reference Include="System">
          <Name>System</Name>
        </Reference>
        <Reference Include="System.Data">
          <Name>System.Data</Name>
        </Reference>
        <Reference Include="System.Xml">
          <Name>System.XML</Name>
        </Reference>
        <Reference Include="Relius.Admin.Base.DataAccess">
          <Name>RELIUS.ADMIN.BASE.DATAACCESS</Name>
          <HintPath>C:\Relius\Admin\v13.0\RELIUS.ADMIN.BASE.DATAACCESS.DLL</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Admin.Bus.InfraStructure">
          <Name>Relius.Admin.Bus.InfraStructure</Name>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Admin.Bus.InfraStructure.dll</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Admin.Bus.Validator">
          <Name>Relius.Admin.Bus.Validator</Name>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Admin.Bus.Validator.DLL</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Admin.QTOutput, Version=13.0.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Admin.QTOutput.DLL</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Admin.QTSQLMap, Version=13.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
        <Reference Include="Relius.Admin.QTTables, Version=13.0.0.0, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Admin.QTTables.DLL</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Logging, Version=2.0.2785.22376, Culture=neutral, processorArchitecture=MSIL">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Logging.dll</HintPath>
          <Private>False</Private>
        </Reference>
        <Reference Include="Relius.Admin.QTPSRqst">
          <SpecificVersion>False</SpecificVersion>
          <HintPath>C:\Relius\Admin\V13.0\Relius.Admin.QTPSRqst.DLL</HintPath>
          <Private>False</Private>
        </Reference>
      </ItemGroup>
      <ItemGroup>
        <Import Include="Microsoft.VisualBasic" />
        <Import Include="Relius.Admin.Base.DataAccess" />
        <Import Include="Relius.Admin.Bus.InfraStructure" />
        <Import Include="Relius.Admin.Bus.Validator" />
        <Import Include="Relius.Admin.QTOUTPUT" />
        <Import Include="Relius.Admin.QTPSRQST" />
        <Import Include="Relius.Admin.QTSQLMAP" />
        <Import Include="Relius.Admin.QTTABLES" />
        <Import Include="System" />
        <Import Include="System.Collections" />
        <Import Include="System.Data" />
        <Import Include="System.Diagnostics" />
        <Import Include="System.IO" />
        <Import Include="System.Runtime.InteropServices" />
        <Import Include="System.Text" />
        <Import Include="System.Xml" />
      </ItemGroup>
      <ItemGroup>
        <Compile Include="AssemblyClassRegister.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="AssemblyInfo.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="clsPlanee.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="OmniDataSet.Designer.vb">
          <AutoGen>True</AutoGen>
          <DesignTime>True</DesignTime>
          <DependentUpon>OmniDataSet.xsd</DependentUpon>
        </Compile>
        <Compile Include="OmniImportParameters.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="OmniImportProcess.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="OmniImportSQL.vb">
          <SubType>Code</SubType>
        </Compile>
        <Compile Include="Planee.Designer.vb">
          <AutoGen>True</AutoGen>
          <DesignTime>True</DesignTime>
          <DependentUpon>Planee.xsd</DependentUpon>
        </Compile>
        <Content Include="OmniDataSet.xsd">
          <Generator>MSDataSetGenerator</Generator>
          <LastGenOutput>OmniDataSet.Designer.vb</LastGenOutput>
        </Content>
        <Content Include="Planee.xsd">
          <Generator>MSDataSetGenerator</Generator>
          <LastGenOutput>Planee.Designer.vb</LastGenOutput>
        </Content>
        <None Include="OmniDataSet.xsx">
          <DependentUpon>OmniDataSet.xsd</DependentUpon>
        </None>
        <None Include="Planee.xsx">
          <DependentUpon>Planee.xsd</DependentUpon>
        </None>
      </ItemGroup>
      <ItemGroup>
        <Folder Include="My Project\" />
      </ItemGroup>
      <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
      <PropertyGroup>
        <PreBuildEvent>
        </PreBuildEvent>
        <PostBuildEvent>
        </PostBuildEvent>
      </PropertyGroup>
    </Project>

     

    Thursday, September 13, 2007 1:55 PM
  • I had a the same issue when working with a Windows Forms Control Library project. Whenever I tried to load the custom user control that I wrote (say, I wanted to load my control to another parent control), I would get the System.BadImageFormatException Assembly Manifest error. I *did* find a fix for my situation, it may not be the same as yours but I hope it helps some people out:

    It turns out that if you are using the .NET Reflection library code within a user control, specifically in the construction of the form, this will lead to the error. I can only presume that Visual Studio Design View tries to partially construct the form object and runs into issues when it gets to the reflection part of the code.

    The quick solution in my case was to split the construction of the form into two parts: regular code and the code that makes use of reflection, (where we stick the reflection code into a second Setup() function). The caveat is that the form user must explicitly call this second Setup() function somewhere in their code.  This method keeps the reflection code from getting called in Design View and avoids the error.


    Wednesday, September 02, 2009 12:53 AM