Slow Cheetah transform failing - c#

In Visual Studio 2012 I have Slow Cheetah version 2.5.10 installed. When building an app that uses Slow Cheetah, the build fails with the following error:
Error 1 The "SlowCheetah.Xdt.TransformXml" task could not be loaded
from the assembly
C:\Users\MyActiveDirectoryAccount\AppData\Local\Microsoft\MSBuild\SlowCheetah\v2.5.10\SlowCheetah.Xdt.dll.
Could not load file or assembly
'file:///C:\Users\MyActiveDirectoryAccount\AppData\Local\Microsoft\MSBuild\SlowCheetah\v2.5.10\SlowCheetah.Xdt.dll'
or one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements
Microsoft.Build.Framework.ITask. C:\Users\MyActiveDirectoryAccount\AppData\Local\Microsoft\MSBuild\SlowCheetah\v1\SlowCheetah.Transforms.targets
When navigating to this directory, I can see the Slow Cheetah files, but the SlowCheetah.Xdt.dll file is missing.
C:\Users\MyActiveDirectoryAccount\AppData\Local\Microsoft\MSBuild\SlowCheetah\v2.5.10\
To triage this, I've:
Rebooted
Un-installed and re-installed Slow Cheetah
Clean and rebuild
None of the above fixed the problem. Any guidance would be appreciated. Thanks!

The answer is in one of the Q & A's (by zendu)
Copy the files from
%APPDATA%..\Local\Microsoft\MSBuild\SlowCheetah\v1.
to
%APPDATA%..\Local\Microsoft\MSBuild\SlowCheetah\v2.5.10.
List of files:
Install-Manifest.xml
Microsoft.Web.XmlTransform.dll
SlowCheetah.Tasks.dll
SlowCheetah.Transforms.targets
SlowCheetah.Xdt.dll
Source
Also see this related question
The "SlowCheetah.Xdt.TransformXml" task could not be loaded from the assembly

I had the same problem with Visual Studio 2010. I just install the SlowCheetah nuget package (install-package SlowCheetah) and after that the build succeed. The nuget package set up correctly the slowcheetah task in your solution.
SlowCheetah nuget Package

Related

Error MSB4062 after building solution with msbuild

I tried to build a solution with a script which uses msbuild.
In VS 2017 it worked perfectly fine, but unfortunately after moving project to computer with VS 2019 I am unable to build it this way.
In few projects of solution I am seeing the same error.
Error MSB4062
: The "CheckPathAttributes" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Ve
rsion=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
On your solution's folder, search for hidden .vs folder and delete the folder. Then open your VS 2019, open the solution, and do clean and rebuild.
Also looking at your error, it also may be caused by the fact that your script needs dependency to MSBUILD 15.0 but you are using VS 2019 and this means MSBUILD v16.0. I suggest you have to update your script as well.
Let me know if it works/solves your problem or not.

MsBuild does not find restored NuGet-Packages on Visual Studio Online

I try to build a solution stored in an external GIT-Repository on Visual Studio Online.
It has the following steps:
1: Git Restore - Works
2: NuGet Restore - Works
3: Build - Does NOT work
My first guess when looking at the logs is that MsBuild is not looking for the Packages where NuGet had stored them.
Some Lines from NuGet Restore:
2018-03-14T21:10:11.0352862Z Completed installation of AngleSharp 0.9.9
2018-03-14T21:10:11.0353230Z Adding package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages'
2018-03-14T21:10:11.0353563Z Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages'
2018-03-14T21:10:11.0354972Z Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\s\packages' from source 'https://api.nuget.org/v3/index.json' 'Microsoft.SharePointOnline.CSOM.16.1.7317.1200' to folder 'D:\a\1\s\packages'
Some lines from MsBuild:
018-03-14T21:10:21.2105399Z PrepareForBuild:
2018-03-14T21:10:21.2105793Z Creating directory "bin\Release\".
2018-03-14T21:10:21.2424947Z Creating directory "obj\Release\".
2018-03-14T21:10:30.3569560Z ResolveAssemblyReferences:
2018-03-14T21:10:30.3570425Z Primary reference "AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL".
2018-03-14T21:10:30.3670272Z ##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
My solution/packages structure is:
....\mysolution\myproject\myproject.csproj
....\mysolution\myproject\packages.config
Current Config:
So how can I change the Nuget and/or msbuild-behavior to make this work?
(Update): To clear this up: I have this problem with every package. They all are in the packages.config, each one is downloaded from Nuget, but each one also isn't found from MsBuild
(Update2) The Commands generated are currently the following:
NUGET:
D:\a\_tool\NuGet\4.4.1\x64\nuget.exe restore D:\a\1\s\AweCsomeO365\packages.config -PackagesDirectory D:\a\1\a\packages -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_22.config
MSBUILD:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "D:\a\1\s\AweCsomeO365\AweCsomeO365.csproj" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_(GUID)\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=(GUID)|SolutionDir=D:\a\1\s\AweCsomeO365"*ForwardingLogger,"D:\a\_tasks\VSBuild_(GUID)\1.126.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=D:\a\1\a /p:ReferencePath=D:\a\1\a\packages /p:platform="anyCPU" /p:configuration="Release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="VSTS_(GUID)_build_4_22
I replaced the GUIDs; tempNuGetConfig is something that seems to be generated by VSTS dynamically
Still. even if the log states that nuget stores the packages
Added package 'AngleSharp.0.9.9' to folder 'D:\a\1\a\packages'
MsBuild does not seem to find them there:
For SearchPath "D:\a\1\a\packages".
2018-03-16T13:57:42.4625155Z Considered "D:\a\1\a\packages\AngleSharp.winmd", but it didn't exist.
2018-03-16T13:57:42.4625456Z Considered "D:\a\1\a\packages\AngleSharp.dll", but it didn't exist.
2018-03-16T13:57:42.4625730Z Considered "D:\a\1\a\packages\AngleSharp.exe", but it didn't exist.
VSTS-Configurationvalues:
MsBuild: /p:ReferencePath=$(Build.StagingDirectory)\packages
Nuget-DestiantionDirectory: $(Build.StagingDirectory)\packages
(update3): I have no solution file, but only a csproj-file in that repository
The issue was that inside the project there was a hintpath for the packages directing to a location that was not within the GIT-Repository (and shouldn't):
<Reference Include="AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>..\..\AweCsome365Test\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
</Reference>
My original approach was to define a target directory to NuGet and a Source Directory for MSBuild to use another location to the packages that both understand.
The issue though (as far as I understand) is, that NuGet always creates a subfolder-structure "./packages/{PackagesName}/lib/net45/{file}" and MSBuild does not look recursivly when setting "./packages" as source path.
The above is just an explanation for the future guy running into the same problem
So my solution was to mimic the local behavior for nuget and changing the output directory to match the HintPath (even if there is no "AweCsome365Test")-directory in the repository:
(I will leave this question open as this solution smells fishy. If anyone has a better solution that allows to chain nuget and msbuild without using the HintPath I am happily willing to spend my bounty on it)
I believe that your MSBuild "ReferencePath" parameter is not correct. you are telling MS Build that all your references (nuget packages and their dlls included) are going to be located at "D:\a\1\a\packages" but that is not where nuget will download and store the packages and dlls. Nuget will download and extract files into D:\a\1\a\packages\{packageName}\{version}\lib\{environment}\package.dll. I think you need to remove that last parameter (ReferencePath) from your MSBuild arguments.
I also noticed that your PackageLocation parameter is not the same as the destination for the NuGet restore task, do you need to add the "\packages" to that parameter like the destination in the restore task?
Change the nuget restore destination directory to $(Build.SourcesDirectory)\packages and remove the msbuild ReferencePath parameter.
The answers here are largely right. However it's worth noting another cause that can result in this behaviour. My toolchain was using Azure DevOps which is basically the same as Visual Studio Online, just a few years later.
Cause:
Reference your project from a different solution (cross-repo), for instance for debugging purposes
Update NuGet references in the problematic project from the external place you referenced it from
What this does is make use of the solution location for packages when the package gets installed.
For .Net core/standard projects, using Update-Package -reinstall appears to fix things. However, for .Net Framework projects, even though packages.json may get rebuilt, the <HintPath /> node in the .csproj gets left as is - with a reference to a packages folder that Azure will never create.
Simple fix:
Right click on the offending solutions locally, and choose Unload
Right click on the unloaded project, choose edit .csproj
Find any hintpaths that look like ../../OtherRepo/packages (the slash in use may vary), and change them to ../packages
Confirm the solution does build locally still
Push the changes to Azure, and cross your fingers
This approach will fix the issue caused by consolidating / updating packages from the wrong place rather than requiring a change to the build pipeline to spoof that location (which in may case, wasn't working very well either).

Different .NET build result when run in Bamboo

I am building a .net 4.5.2 application using Atlassian Bamboo. The build has been operating fine with dependencies on Telerik.Windows.Controls.Data for several weeks.
On a recent feature branch I have added a dependency on Telerik.Windows.Controls.GridView.dll version 2015.3.1104.45. Now the build is failing.
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "Telerik.Windows.Controls.GridView,
Version=2015.3.1104.45, Culture=neutral,
PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL". Check to
make sure the assembly exists on disk. If this reference is required
by your code, you may get compilation errors. 24-Dec-2015 08:11:23
error MC3074: The tag 'RadGridView' does not exist in XML namespace
'http://schemas.telerik.com/2008/xaml/presentation'. Line 55 Position
18.
As is traditional when builds fail, I followed these triage steps:
Checkout the offending commit and test build on my workstation
If it "works on my machineā„¢", log in to the build server and test build using the working directory that failed
I build both steps in the visual studio 2015 IDE. In this instance - both builds succeed. Frustrating! So I take to the command line and build the solution using the command line executed by Bamboo:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com" "SolutionNameRedacted.sln" /rebuild Release
This also succeeds!
I noticed the following line in the bamboo log:
24-Dec-2015 08:10:23
C:\Atlassian\Data\Bamboo\xml-data\build-dir\CS-CC13-JOB1>call
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"
amd64 24-Dec-2015 08:10:23 '"C:\Program Files (x86)\Microsoft Visual
Studio 14.0\VC\vcvarsall.bat"' is not recognized as an internal or
external command,
This batch file is used to specify the compiler toolset. Is it a problem that it is not found? I always assumed compiler preferences were expressed by the project files. I have checked the Microsoft Visual Studio 14.0 directory and vcvarsall.bat does not exist anywhere.
The only significant change to the csproj file since it last built is the addition of this line:
<Reference Include="Telerik.Windows.Controls.GridView, Version=2015.3.1104.45, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL" />
I am at a bit of a loss as it is causing delivery to slip massively.
My current theory is that it is a user account issue and bamboo does not have access the to Telerik assembly it needs. My next steps are too:
References the assembly using clr-namespace in the xaml file that is breaking
Test the build on a user account with elevated permissions (sadly i don't have that kind of access)
As it turns out, Telerik do not install their binaries to the GAC. Visual Studio require a <hintpath> entry in the csproj file to help discovery. This path should be to you install directory.
Does this sound like a faff? It is abd I'm not terribly impressed. Thankfully the Telerik VS Extension will add the reference and hintpath for you. My recommendation is to always use this wizard.
The downside - all of your developers need the Telerik library installed in the same folder. I'm pretty sure you can manually register binaries with the GAC to skirt this.

Reference Microsoft.VisualStudio.QualityTools.UnitTestFramework for CI build

I have created a C# test project in VS2015 RC. it builds locally but when i attempt to build on our CI build server (TeamCity) it fails with errors:
UnitTest1.cs(2,17): error CS0234: The type or namespace name
'VisualStudio' does not exist in the namespace 'Microsoft' (are you
missing an assembly reference?)
[... .Tests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name
'TestMethod' could not be found (are you missing a using directive or
an assembly reference?)
[... .Tests.csproj]
Clearly this is because the assembly containing these namespaces (Microsoft.VisualStudio.QualityTools.UnitTestFramework) is not on the build server; on my local machine it resides at C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.
I could copy the assembly into my solution so that it becomes part of the codebase but manually moving files feels like a bit of an inelegant hack. I searched around on nuget and found http://www.nuget.org/packages/Microsoft.VisualStudio.QualityTools.UnitTestFramework/ which I figured would do the trick, but installing that package failed with:
Install-Package : Could not install package
'Microsoft.VisualStudio.QualityTools.UnitTestFramework 11.0.50727.1'.
You are trying to install this package into a project that targets
'.NETFramework, Version=v4.5.2', but the package does not contain any
assembly references or content files that are compatible with that
framework
What's my best option of solving this? I'm surprised that creating a test project in VS2015 does not automatically include all the dependencies that I need, though perhaps I'm being naive (I'm something of a fledgling dot netter).
The answer is similar to option 1 in eng.augusto's answer.
Microsoft doesn't provide NuGet for the latest version of Microsoft.VisualStudio.QualityTools.UnitTestFramework,
but rather supplies it as a part of Visual Studio
(normally at C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)
I created the folder Microsoft.VisualStudio.QualityTools as a subfolder of my solution and copied:
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Microsoft.VisualStudio.QualityTools.UnitTestFramework.xml
The files should be added to source control (even if DLLs are usually ignored).
Then I changed references in my Test.csproj to refer to a new location.
Hmm I have some ideas, so choose the one that best fits your needs
A simple answer should be mark the DLL to copy local and use a folder like Assemblies in the same folder of the solution and references "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll"
Install Visual Studio in your build server. Sounds nuts but it's the closest to "developer machine" that you have.
Install the DLL in the GAC so you don't have to bother with this.
Fix the NuGet package (Adding a reference for the .NET Framework version) and use it.
Downgrade your .NET Framework version so you can use the NuGet package.
Create your own NuGet server! (and add the reference of the DLLs you need).
IMHO I'd choose the first answer, because it seems to be the "best way" to use NuGet to resolve all your packages problems but you are using a DLL that you don't know if it should be trusted.
In system used in "old" languages like C, or C++ it's common you download the source code and the libraries needed for the code to run so I do not think the NuGet package it's the best solution.
Using the first option you always have the same version and could check the MD5 of the file and know exactly what is running in your build server.
Maybe the real best option should be 6. When you use your own NuGet server to handle your DLLs making your live more awesome and trustable.
For projects created in VS 2017. Adding Nuget package Microsoft.VisualStudio.QualityTools.UnitTestFramework.Updated allows to build unit test projects on CI without VS installed on build server:
I was having this issue when trying to use MSBuild on our dev server via our CI/CD process after I was asked to uninstall VS2013 from our dev server by our IT team.
In my case in my build output there were a few lines with the word Considered. What this means is that the build is considering those folders for locations where the file may be located. One of those lines was as follows:
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll", but it didn't exist.
I copied Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll from my local machine to that folder on the dev server and the error went away.
Of course Microsoft does a s...t job. To fix this, you need to copy the dll's to some convinint lication and reference them from your ptoject .csproj file.
<HintPath>..\packages\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="QualityTools-Fakes">
<HintPath>..\packages\Microsoft.QualityTools.Testing.Fakes.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
I don't understand why when we add this from VSudio it does not update the same file instead no one has an idea what it does. In Java you have a single file pom.xml or build.gradle, nothing else. In C# there is all sorts of stuff which adds no value but confusion.

Unable to load DLL 'SQLite.Interop.dll'

Periodically I am getting the following exception:
Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I am using 1.0.82.0. version, installing it with nuget in VS2010, OS Win7 64.
Once exception starts to appear, it appears constantly - in debug and release and running application within or outside VS.
The only way to stop it is logoff and logon. The exception is not thrown and dll is loaded.
It can work for days, but then it can break again.
Has anyone seen something like this and is there a solution for it?
I know I'm late to the party but I had this issue right after I pulled down latest x86/x64 today (version 1.0.88.0). My local IIS in VS2012 runs 32bit by default and there's no easy way to switch to x64. My production server runs 64bit.
Anyway I installed the NuGet package to a DLL project and I got this error. What I had to do to get it working I had to install it to the main site project, too. Even if it doesn't touch SQLite classes at all.
My guess is that SQLite uses the entry assembly to detect which version of Interop to load.
I had this problem because a dll I was using had Sqlite as a dependency (configured in NuGet with only the Sqlite core package.). The project compiles and copies all the Sqlite dll-s except the 'SQLite.Interop.dll' (both x86 and x64 folder).
The solution was very simple: just add the System.Data.SQLite.Core package as a dependency (with NuGet) to the project you are building/running and the dll-s will be copied.
So, after adding the NuGet the deployment doesn't copy down the Interops. You can add this to your csproj file and it should fix that behavior:
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
If you look in the source for NuGet for SQLite you can see what these are doing specifically. This allowed me to get a deploy working with ASP.Net Core.
I had this same problem when using SQLite in a WPF project whose platform target was Any CPU. I fixed it by following the following steps:
Open the project designer in Visual Studio. Details on how to do it can be found here.
Click on the Build tab.
Disable the prefer 32-bit option.
Alternatively, you could just set the platform target to x86 or x64. I think this problem is caused by the System.Data.SQLite library using the platform target to get the location of the 'SQLite.Interop.dll' file.
UPDATE:
In case the project designer cannot be reached, just open the project (*.csproj) file from a text editor and add the value <Prefer32Bit>false</Prefer32Bit> into the <PropertyGroup>...</PropertyGroup> tag.
Example code
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>[Set by Visual Studio]</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>[Set by Visual Studio]</RootNamespace>
<AssemblyName>[Set by Visual Studio]</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>[Set by Visual Studio]</FileAlignment>
<!--Add the line below to your project file. Leave everything else untouched-->
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
This is how I fixed it in my project.
It was working, and when a colleague submitted his changes, I received the "Unable to load DLL 'SQLite.Interop.dll'" exception.
Diffing the project's .csproj file, this was in the NON-WORKING version:
<ItemGroup>
<Content Include="x64\SQLite.Interop.dll" />
<Content Include="x86\SQLite.Interop.dll" />
</ItemGroup>
And this is what the WORKING version had:
<ItemGroup>
<Content Include="x64\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="x86\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
After reverting back, I didn't receive the exception. The DLL files were dumped in the appropriate Debug\x64 (etc) folders.
When you get in this state, try performing a Rebuild-All. If this fixes the problem, you may have the same issue I had.
Some background (my understanding):
SQLite has 1 managed assembly (System.Data.SQLite.dll) and several
platform specific assemblies (SQLite.Interop.dll). When installing
SQLite with Nuget, Nuget will add the platform specific assemblies to your project
(within several folders: \x86, \x64), and configures these
dlls to "Copy Always".
Upon load, the managed assembly will search for platform
specific assemblies inside the \x86 and \x64 folders. You can see
more on that here. The exception is this managed
assembly attempting to find the relevant (SQLite.Interop.dll) inside
these folders (and failing).
My Scenario:
I have 2 projects in my solution; a WPF app, and a class library. The WPF app references the class library, and the class library references SQLite (installed via Nuget).
The issue for me was when I modify only the WPF app, VS attempts to do a partial rebuild (realizing that the dependent dll hasn't changed). Somewhere in this process, VS cleans the content of the \x86 and \x64 folders (blowing away SQLite.Interop.dll). When I do a full Rebuild-All, VS copies the folders and their contents correctly.
My Solution:
To fix this, I ended up adding a Post-Build process using xcopy to force copying the \x86 and \x64 folders from the class library to my WPF project \bin directory.
Alternatively, you could do fancier things with the build configuration / output directories.
I had the same issue running Visual Studio Express 2013. I tried several solutions mentioned here and elsewhere to no avail. I hope this fix helps others.
I fixed it by using the DeploymentItem attribute on my test class that tests the SQLite-based service.
Example:
[TestClass]
[DeploymentItem(#"x86\SQLite.Interop.dll", "x86")] // this is the key
public class LocalStoreServiceTests
{
[TestMethod]
public void SomeTestThatWasFailing_DueToThisVeryIssue()
{
// ... test code here
}
}
This causes the needed SQLite.Interop.dll to get copied to the x86 directory within the appropriate "TestResults" folder.
All is green. All is good.
Updating NuGet from Tools -> Extension and updates and reinstalling SQLite.Core with the command PM> Update-Package -reinstall System.Data.SQLite.Core fixed it for me.
old project file format
i.e. projects beginning with <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Add the following to your csproj on your "main"/root project
<PropertyGroup>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<CopySQLiteInteropFiles>false</CopySQLiteInteropFiles>
<CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles>
<CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles>
</PropertyGroup>
new SDK project file format
i.e. projects beginning with <Project Sdk="Microsoft.NET.Sdk.*">
Add PrivateAssets="none" to each ProjectReference/PackageImport in the dependency chain down to the System.Data.Sqlite PackageImport
ex:
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.110" PrivateAssets="none"/>
I had a similar issue in a multiple projects solution. The SQLite.Interop.dll was necessary for one of the plugins distributed with the software using ClickOnce.
As far as debugging in visual studio everything worked fine, but the deployed version was missing the folders x86/ and x64/ containing that DLL.
The solution to have it work after deployment using ClickOnce was to create in the startup project of the solution (also the one being published) these two subfolder, copy into them the DLLs and set them as Content Copy Always.
This way the ClickOnce publishing tool automatically includes these files and folders in the manifest and deploys the software with them
There are really a lot of answers here, but mine is simple and clear with no-GAC-playing-around.
The problem was, the executable File needs a copy of the right SQLite.Interop.dll (x86 or x64) to access our Database.
Mostly architectures have layers and in my case the Data Layer has the required DLL for SQLite Connection.
So i simple put a post build script into my Data Layer Solution and everything worked fine.
TL;DR;
Set all Projects of your solution to x86 or x64 in the build options.
Add following Post-Build-Script to the Project with the SQLite nuget Package:
xcopy "$(TargetDir)x64" "$(SolutionDir)bin\Debug\" /y
Of course you have to change the script for Release Build and x86 builds.
STL;DR;
Put your SQLite.Interop.dll next to the *.exe File.
The default installation of the multi-architecture (x86, x64) version of SQLite from NuGet exhibits the behavior that you described. If you would like to load the correct version for actual architecture that the .NET runtime chose to run your application on your machine, then you can give the DLL loader a hint about where to locate the correct library as follows:
Add a declaration for the kernel32.dll function call to SetDLLDirectory() before your Program.Main():
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true)]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
static extern bool SetDllDirectory(string lpPathName);
Then use your own method for determining the correct subdirectory to find the architecture specific version of 'SQLite.Interop.dll'. I use the following code:
[STAThread]
static void Main()
{
int wsize = IntPtr.Size;
string libdir = (wsize == 4)?"x86":"x64";
string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
SetDllDirectory(System.IO.Path.Combine(appPath, libdir));
even if it is an old post, I'd like to share the solution that I found here:
http://system.data.sqlite.org/index.html/info/54e52d4c6f
If you don't want to read all the issue, the solution is to copy the file "msvcr100.dll" (that can be found in Windows\System32 directory) in the same path as SQLite.Interop.dll.
I would advice to read the issue to understand why, and to include the file in your setup but to install it only if the error occurs, I made it an optional component selectable in the setup options.
HTH,
Formentz
I don't know why this has not been included yet, but I had to do the research and find this out for myself, so hopefully someone will find this answer and be saved the trouble. This was for a WPF app. It worked fine on my Dev box, but did not work on the computer where I was copying it and got the Unable to load DLL 'SQLite.Interop.dll' error. I ported over all of its associated directories and files, directly from my "Debug" folder to this other computer when I got the same error as the OP when I ran it. My "bin" folder that contained my DLLs had been copied to "Debug\bin" and all were included, along with my application files when I did my copying to the other computer using this path, so it was not missing any files.
Things I saw said in other answers that did not apply:
I did not use the NuGet package or need to create x86 or x64 folders that it seems that NuGet package creates. My DLLs (System.Data.SQLite and SQLite.Interop.dll, along with System.Data.SQLite.config) are in the "bin" folder in my project and were copied in manually (create "bin" folder in Solution Explorer in VS, paste DLLs into this folder in Windows Explorer, use Add > Existing Item to bring files into VS folder/project). Then I reference them as Referenced Assemblies in my project using that location ("References" > "Add Reference", and browse to one, rinse, repeat for the rest). This ensures my project knows exactly where they are.
I did not need to reference any SQLite DLL file in my app.config or even touch my MyProject.csproj file.
I did not even need to specify a particular processor! My project's build is for "Any CPU", even though I have only mixed or 64-bit DLLs and will only be running on Windows 7+, which are 64-bit OSes. (no x86-only/32-bit solely DLLs)
I was already specifying them as "Content" and "copy if newer" for these DLLs when I experienced the OP's error.
What I found was this, from https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q20 :
(11) Why do I get a DllNotFoundException (for "sqlite3.dll" or "SQLite.Interop.dll") when trying to run my application?
Either the named dynamic link library (DLL) cannot be located or it cannot be loaded due to missing dependencies. Make sure the named dynamic link library is located in the application directory or a directory along the system PATH and try again. Also, be sure the necessary Visual C++ runtime redistributable has been installed unless you are using a dynamic link library that was built statically linked to it.
Emphasis mine on that bolded part inside the paragraph. The target computer was fresh and had no programs loaded except .NET 4.0. Once I installed C++, it was able to complete the commands to SQLite. This should have been one of the first FAQs and part of the pre-requisities, but it was buried at #11. My development computer already had it loaded because it came with Visual Studio, so that's why it worked, there.
Download:
Visual C++ Redistributable for Visual Studio 2015:
https://www.microsoft.com/en-us/download/details.aspx?id=48145
Update 3 (cumulative update):
https://www.microsoft.com/en-us/download/details.aspx?id=53587
As the SQLite wiki says, your application deployment must be:
So you need to follow the rules. Find dll that matches your target platform and put it in location, describes in the picture. Dlls can be found in YourSolution/packages/System.Data.SQLite.Core.%version%/.
I had problems with application deployment, so I just added right SQLite.Interop.dll into my project, the added x86 folder to AppplicationFolder in setup project and added file references to dll.
I had the same issue. Please follow these steps:
Make sure you have installed System.Data.SQLite.Core package by
SQLite Development Team from NuGet.
Go to project solution and try to locate build folder inside packages folder
Check your project framework and pick the desired SQLite.Interop.dll and place it in your debug/release folder
Reference
Copy "SQLite.Interop.dll" files for both x86 and x64 in debug folder. these files should copy into "x86" and "x64 folders in debug folder.
You could also get this error if you are trying to run a 32 bit dll, in a 64 bit project.
I got this when I have placed the same file(SQLite.Interop.dll in 32 bit version) in both the x86 and x64 folder.
If you download correct binary for SQLite then copy SQLite.Interop.dll into your Release or Debug folder according to your project build option.
I have started using Costura.Fody to package (.net) assemblies and embed and preload native dlls. This also helps later, with distribution as you can send one file.
Install Costura Fody from Nuget.
In your C# project create a folder called costrua32. In there add any native dlls you which C# to load.
Once you have added them to this folder. Click on the properties window and change build action to "Embedded Resource"
Finally you need to amend the XML file called FodyWeavers.xml as follows. Here I am specifying load the sql dll first. (note you drop the .dll)
Weavers
Costura
PreloadOrder
SQLite.Interop
tbb_debug
tbb
/PreloadOrder>
/Costura
/Weavers
The advantage of this is that you do not have to write any pre or post build events, and the end product is totally encapsulated in to one larger file.
Also added the dll to the test project (through Nuget Manager) and it fixed it.
Could there be contention for the assembly? Check to see whether there's another application with a file lock on the DLL.
If this is the reason, it should be easy to use a tool like Sysinternal's Process Explorer to discover the offending program.
HTH,
Clay
I had this problem because Visual C++ 2010 redistributable no installed in my PC.if you have not already installed Visual c++ 2010 redistributable Download and install this(check x86 or 64 dll).
I got the same problem. However, finally, I can fix it. Currently, I use Visual Studio 2013 Community Edition. I just use Add->Existing Item... and browse to where the SQLite.Data.SQLite files are in (my case is 'C:\Program Files (x86)\System.Data.SQLite\2013\bin'). Please don't forget to change type of what you will include to Assembly Files (*.dll; *.pdb). Choose 'SQLite.Interop.dll' in that folder. From there and then, I can continue without any problems at all. Good luck to you all. ^_^
P.S. I create web form application. I haven't tried in window form application or others yet.
Try to set the platform target to x86 or x64 (and not Any CPU) before you build:
Project->Properties->Build->Platform target in Visual Studio.
Copy SQLite.Interop.dll in project directory.
src\
project\
bin\ <-- Past in bin
x64\
SQLite.Interop.dll <-- Copy this if 64
x86\
SQLite.Interop.dll <-- Copy this if 32
I've struggled with this for a long time, and, occasionally, I found that the test setting is incorrect. See this image:
I just uncheck the test setting, and the issue disappears. Otherwise, the exception will occurs.
Hopefully, this will help someone.
Not sure it's the root cause.
My application is a web application (ASP.NET MVC) and I had to change the application pool to run under LocalSystem instead of ApplicationPoolIdentity. To do this:
Open IIS Manager
Find the Application Pool your site is running under.
Click Advanced Settings from the actions
Change Identity to LocalSystem
I have no idea why this fixes the issue.
My situation was a little unique. I was running an application inside a docker container and kept getting the following error
System.DllNotFoundException : Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libSQLite.Interop.dll: cannot open shared object file: No such file or directory
So I set LD_DEBUG=libs to find out what folders System.Data.SQLite.dll was looking in to find SQLite.Interop.dll.
You can find info on setting LD_DEBUG here: http://www.bnikolic.co.uk/blog/linux-ld-debug.html
Once I did that I realized that SQLite.Interop.dll was being found just fine. The DLL that wasn't being found was libSQLite.Interop.dll. I should have read the entire error message.
Hours of Googling later I found this guide on how to compile the missing DLL from the SQLite source code.
Note that the file that was actually missing was libSQLite.Interop.dll.so
Anyway when you compile the source code you get libSQLite.Interop.so which you need to rename to libSQLite.Interop.dll.so and put it in the directory that it's looking in which you can find by setting LD_DEBUG.
For me the directory that System.Data.SQLite.dll was looking in was /usr/lib/x86_64-linux-gnu/
Upgrading to Visual Studio 2019 ver. 16.10 caused the issue for me, where msbuild reported the following for the System.Data.SQLite.Core-package:
CopySQLiteInteropFiles:
Skipping target "CopySQLiteInteropFiles" because it has no outputs.
https://github.com/dotnet/msbuild/issues/6493
Microsoft says the bug has been fixed with ver. 16.10.4. Now just have to wait for AppVeyor to update their Visual Studio Images (Until then one can use Previous Visual Studio 2019).
Now AppVeyor is using broken dotnet-build-engine for both current and previous Visual Studio 2019-image. Now one have to explicit install dotnet sdk ver. 5.0.302:
Invoke-WebRequest -Uri 'https://dot.net/v1/dotnet-install.ps1' -UseBasicParsing -OutFile "$env:temp/dotnet-install.ps1"; & $env:temp\dotnet-install.ps1 -Architecture x64 -Version 5.0.302 -InstallDir "$env:ProgramFiles\dotnet"

Categories