FlexCel c# Issue with opening xlsx but not xls


I believe that there is a compatibility issue of FlexCel for .Net with Windows 7 x64 ans latest system patches from Microsoft.

When creating a FlexFile for an .xlsx, I get this exception:

A first chance exception of type 'System.Security.VerificationException' occurred in FlexCel.dll

However, it works fine when opening the FlexFile with the corresponding ".xls". The Excel is a new blank sheet containing a text in the first cell (no macros, no functions, etc.).

I have tested this both with a Windows application and a unit test project. I also ran Visual Studio as administrator. The files on disk are not read-only or subject to any security restrictions.

The assembly used is the latest version My machine is Windows 7 x64. All security updates from Microsoft are installed. Strangely, the code above still worked a few weeks ago when we started testing. Hence, maybe FlexCel has a problem with some of Microsoft updates.

The code is:

I found the problem. Very strange.

The "Target Platform" of the VS project must be "Any CPU". If you put "x86" you get the security warning mentioned above, There must be a bug in FlexCel regarding the WindowsBase assembly - the exception shows up just after loading that assembly.


This is strange. We develop here with Windows7 x64 with the latest patches, and haven't seen any issue.WindowsBase is indeed only used in xlsx, but we haven't seen problems here. And I can't think on any bug loading WindowsBase.dll, since we don't load it ourselves, it is just a referenced assembly like all the others.

Could you have some corrupted windowsbase, or one with the wrong permissions?

I have tried it here with the latest patches setting FlexCel to anycpu, x86 or x64 and it always worked fine. (of course it didn't work if you tried to call an x86 assembly from an x64 app or viceversa, but that is expected, you can't call 64bit code from 32 or 32 from 64).

In any case, there is no reason to compile FlexCel in anything else than AnyCpu, since it is a fully managed assembly and it will run in 64bits when called from 64bits, and in 32bits when called form 32 bits. And you can't mix 64bit with 32 anyway.

(If I understood correctly and you were compiling FlexCel in x86). If it is your own application which you set to AnyCpu, that is not recommended by  Microsoft, and that's why it defaults to x86 for applications you create. AnyCpu used in apps can bring trouble since some of your users will be using a 32bit app and some others a 64 bit app doubling your possible bugs.

Back to the problem, are you seeing this in more than 1 machine?  As said, we didn't see it here and we haven't got any report from any other customer about an issue like this. Couldn't this be some permissions you changed in your machine?

Also is this .NET 3.5 or 4?



We are using .Net 4 and VS 2010.

As you say, it must have been the x86 target setting that caused the problem (I hope so).

This said, I still cannot open the xlsx from a unit test project - the security error is coming up each time whatever the project settings. I switched to a Windows app for the tests. That is fine for me.

If you google the VerificationException you will find similar problems mostly related to unit test environments. I am wondering if you would see the error when debugging a unit tests.

I will test on another PC and post results tomorrow.

We don't use a standard unit test framework here, we heave our own (pertly because we have it since before it existed in .net, and partly because we can customize more our own framework). But at least our tests aren't showing any problems, and I tried creating a simple "standard" test with visual studio, and it also work fine.

Also, this exception seems to be related to having invalid IL, but FlexCel is fully managed and you can verify the IL:
C:\Users\adrian\Documents\TMSSoftware\FlexCelNET\NET40>peverify /il FlexCel.dll

Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

All Classes and Methods in FlexCel.dll Verified.

Not really sure on what can be happening. Let me know your results in other machine.