locked
Referenced native libraries getting pre-compiled and then throwing exception

    Question

  • Hi I have an issue in the universal app. I am referencing Nokia.Graphics.Imaging.dll and WindowsPreview.Media.Ocr.dll in the universal app project. Everything compiles and runs on every device I tested it with. The problem is that after some time NGen kicks in and pre-compiles my DLLs, including the native ones. These DLLs then get corrupt and next time I run the app I get BadImageFormatException due to an attempt to load the <nativelibrary>.ni.dll. Is this a bug of NGen? When I delete these <nativelibrary>.ni.dll files the app runs again.

    Friday, March 6, 2015 9:53 AM

All replies

  • Hi LVolf,

    I've not encountered this issue before, could you please provide a minimized demo(Remove sensitive data) to us? We need it to narrow down issue on our sides.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 9, 2015 1:58 AM
    Moderator
  • Hi, unfortunately, I was not able to simulate this behavior in another project so far. Here http://uloz.to/xRShw487/precompiled-zip are NGENed files from our application (_not_working folder) and from a filter-manager sample (_working from different_app). As you can see for some reason Lumia.Imaging.ni.dll in our app has only 796kB, while from the other app it has 1235kB.

    The NGEN log file looks ok to me:

    03/23/2015 15:18:24.272 [11796]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\Lumia.Imaging.Managed.DLL (CLR v4.0.30319) ...
    03/23/2015 15:18:24.350 [11796]: ngen returning 0x00000000
    03/23/2015 15:18:25.334 [24168]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\WindowsPreview.Media.Ocr.winmd (CLR v4.0.30319) ...
    03/23/2015 15:18:25.365 [24168]: ngen returning 0x00000000
    03/23/2015 15:18:25.444 [8036]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\Lumia.Imaging.winmd (CLR v4.0.30319) ...
    03/23/2015 15:18:25.725 [8036]: ngen returning 0x00000000

    Once I delete Lumia.Imaging.ni.dll and WindowsPreview.Media.Ocr.ni.dll, the app starts working again. Lumia.Imaging.Managed.DLL seems to be OK and does not cause any troubles, maybe because it is managed, while both of the problematic DLLs are native already.


    • Edited by LVolf Monday, March 23, 2015 4:53 PM
    Monday, March 23, 2015 2:43 PM
  • Hi, unfortunately, I was not able to simulate this behavior in another project so far. Here http://uloz.to/xRShw487/precompiled-zip are NGENed files from our application (_not_working folder) and from a filter-manager sample (_working from different_app). As you can see for some reason Lumia.Imaging.ni.dll in our app has only 796kB, while from the other app it has 1235kB.

    The NGEN log file looks ok to me:

    03/23/2015 15:18:24.272 [11796]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\Lumia.Imaging.Managed.DLL (CLR v4.0.30319) ...
    03/23/2015 15:18:24.350 [11796]: ngen returning 0x00000000
    03/23/2015 15:18:25.334 [24168]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\WindowsPreview.Media.Ocr.winmd (CLR v4.0.30319) ...
    03/23/2015 15:18:25.365 [24168]: ngen returning 0x00000000
    03/23/2015 15:18:25.444 [8036]: 1>    Compiling assembly C:\Program Files\WindowsApps\app\Lumia.Imaging.winmd (CLR v4.0.30319) ...
    03/23/2015 15:18:25.725 [8036]: ngen returning 0x00000000

    Once I delete Lumia.Imaging.ni.dll and WindowsPreview.Media.Ocr.ni.dll, the app starts working again. Lumia.Imaging.Managed.DLL seems to be OK and does not cause any troubles, maybe because it is managed, while both of the problematic DLLs are native already.



    Hi LVolf,

    >>I am referencing Nokia.Graphics.Imaging.dll and WindowsPreview.Media.Ocr.dll in the universal app project

    How did you add these references in your project? Basically, the NuGet package is the easiest way, for example:

    See the NuGet documentation for all the ways you can download and install the NuGet package in your project. To install the package from within Microsoft Visual Studio, do the following:
    1.In Visual Studio, select PROJECT | Manage NuGet Packages.
    2.In the Online section, select nuget.org. Search for  Microsoft.Windows.Ocr.
    3.Click Install.
    4.Select BUILD | Configuration Manager to change the build configuration of your project from AnyCPU to x86, x64, or  ARM.
    5.If Intellisense does not work after you have installed the NuGet package, unload and reload the Visual Studio project. In Solution Explorer, right-click the project and select Unload Project. Then right-click the project again and select  Reload Project.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 1:18 PM
    Moderator
  • I know NuGet is the easiest way, but it does not work well with our build system which is why I cannot use it. Instead of using NuGet in our project, I created a sample project, used NuGet to get all DLLs and then copy+pasted this into our vcproj file:

     <ItemGroup Condition=" '$(MSBuildProjectExtension)' == '.csproj' Or '$(MSBuildProjectExtension)' == '.vbproj' ">
      <Reference Include="Lumia.Imaging.Managed">
       <HintPath>$(MSBuildThisFileDirectory)\..\..\lib\win81-hidden\$(Platform)\Lumia.Imaging.Managed.dll</HintPath> 
      </Reference>
      <Reference Include="Lumia.Imaging">
       <HintPath>$(MSBuildThisFileDirectory)\..\..\lib\win81\$(Platform)\Lumia.Imaging.winmd</HintPath> 
      </Reference>
      <Reference Include="Lumia.InteropServices.WindowsRuntime">
       <HintPath>$(MSBuildThisFileDirectory)\..\..\lib\win81\$(Platform)\Lumia.InteropServices.WindowsRuntime.winmd</HintPath>    
      </Reference>
     </ItemGroup>

     <ItemGroup>
      <SDKReference Include="Microsoft.VCLibs, Version=12.0">
       <Name>Microsoft Visual C++ 2013 Runtime Package for Windows</Name>
      </SDKReference>
     </ItemGroup>

    This should do the same thing as NuGet does, right?

    Thursday, March 26, 2015 9:51 AM