c#報System.BadImageFormatException
項目內(nèi)使用了第三方的非托管dll庫,導(dǎo)致運(yùn)行拋出如下異常:
未處理System.BadImageFormatException
Message: “System.BadImageFormatException”類型的未經(jīng)處理的異常在 XD.Vision.exe 中發(fā)生
其他信息: 試圖加載格式不正確的程序。 (異常來自 HRESULT:0x8007000B)
原因
第三方dll的目標(biāo)運(yùn)行平臺與項目不一致。直接在項目屬性內(nèi)設(shè)置目標(biāo)平臺環(huán)境,可能仍會失敗(因該項目的 csproj文件內(nèi)有冗余的配置項導(dǎo)致失敗)
解決辦法:
用文本工具打開問題項目的 csproj文件,直接修改,如有冗余配置項則刪除。
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
<Prefer32Bit>false</Prefer32Bit>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
浙公網(wǎng)安備 33010602011771號