Building with code contracts on AppHarbor

I am trying to deploy my first application hosted on AppHarbor and have encountered a problem with my build. Everything builds fine until code contracts try to rewrite assemblies. Error in the log:

CodeContractsRunCodeAnalysisInternal: CodeContracts: Task manager is unavailable (unable to run in background). CodeContracts: ABC: Run static contract analysis. CodeContracts: ABC: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified. CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.SQLCacheDataAccessor.GetMetadataOrNull(String key, Boolean silent) CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.CacheManager`11.TestCache() CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.CacheManager`11..ctor(Dictionary`2 methodAnalyses, Dictionary`2 classAnalyses, GeneralOptions options) CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.CacheManager`11.Create(Dictionary`2 dictionary, Dictionary`2 dictionary_2, GeneralOptions generalOptions) CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.Clousot.TypeBinder`9..ctor(String[] args, IDecodeMetaData`9 mdDecoder, IDecodeContracts`5 contractDecoder, IDictionary assemblyCache, Action`3 setTargetPlatform, IOutputFullResultsFactory`2 externalOutputFactory) CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.Clousot.ClousotMain[Local,Parameter,Method,Field,Property,Event,Type,Attribute,Assembly](String[] args, IDecodeMetaData`9 mdDecoder, IDecodeContracts`5 contractDecoder, IDictionary assemblyCache, Action`3 setTargetPlatform) CodeContracts: ABC: at Microsoft.Research.CodeAnalysis.CCI1Driver.Main(String[] args) CodeContracts: ABC: CodeContracts: ABC: Static contract analysis done. 

I know that when creating locally with Visual Studio, the contract code runs in the background thread. Perhaps AppHarbor does not allow creating such streams for this? But what error is missing in the System.Data.SqlServerCe.dll? My code is sure that it is not using it, but maybe contracts with MS code are being executed?

It’s just interesting if someone successfully deployed the code with the code contracts in it in AppHarbor, and if so, what did you do to make it work? It may be necessary for SQL Server CE to install AppHarbor for the code contracts to work. Oh, and my assembly does not create a reference assembly of the contract code, it just tries to do a static check and does a rewrite to do runtime checks.

Finally, I tried to disable code contracts from AppHarbor.sln, but this option is a project setting, not a solution setting, so it also disables them for my regular solution file.

+4
source share
3 answers

Figured it out. .NET Code Contracts (the System.Diagnostics.Contracts namespace, for those who don’t know) has a function that can perform static code analysis based on the contracts that have been placed in the code. If you have the Visual Studio Add-in for Code Contracts installed, you can go to the VS project property pages and click on the Code Contract tab. The Static Checking section has the Cache Results option. If you enable this, static checking uses the built-in SQL Server database at build time to do everything it does to analyze static code faster (apparently this file will be stored in your project directory between compilers). This is the dependency that the build server has in SQL CE; it has nothing to do with the runtime for the application.

Since AppHarbor does not have SQL CE on its build servers, I did it to change the properties of each code in my projects. Perform verification of contract execution and perform static contract verification for both debug assembly and release, but the "Create assembly of cache results" option in the "Static contract verification" section is disabled. (Note also that since AppHarbor does not allow you to perform background tasks from Visual Studio, you must also disable the Check in Background option in the "Checking a Static Contract" section.)

Why does it seem to me that I'm the only one that uses the System.Diagnostics.Contracts namespace (other than the .NET Framework itself)?

+4
source

I am not very familiar with Code Contracts, but the problem may be that you are missing SQL Server CE. You might want to try a project that does not use SQL Server CE for validation. Consider adding SQL Server CE using NuGet or a build for deploying bin to make it available when AppHarbor starts your build. There is more information in this blog post .

0
source

Although every error message that Code Contracts generates suggests that you need to install SQL Server CE 3.5.1, you really need to install version 3.5.2 .

Uninstalling all other versions of SQL Server CE 3.5.x and installing this made me work. And yes, you really need both 32 and 64 bit versions if you are on a 64-bit machine.

0
source

Source: https://habr.com/ru/post/1442384/


All Articles