[英]When running test project in Dot Net 4.6.1, SQLitePCLRaw throws TypeInitializationException
I have a test project targeting net452
, net461
, and netcoreapp20
.我有一个针对
net452
、 net461
和netcoreapp20
的测试项目。 Everything runs fine under net452
and netcoreapp20
, however, when I run net461
I get a System.TypeInitializationException
在
net452
和netcoreapp20
下一切运行良好,但是,当我运行net461
时,我得到一个System.TypeInitializationException
here is the stack trace这是堆栈跟踪
Unhandled exception: System.TypeInitializationException: The type initializer for "MyApp.SomeClass" threw an exception. ---> System.ArgumentException: Path is invalid.
in System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
in System.IO.Path.InternalGetDirectoryName(String path)
in SQLitePCL.NativeLibrary.MakePossibilitiesFor(String basename, Assembly assy, Int32 flags, LibSuffix suffix)
in SQLitePCL.NativeLibrary.MyLoad(String basename, Assembly assy, Int32 flags, Action`1 log)
in SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
in SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
in SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
in SQLitePCL.Batteries_V2.Init()
I check the project output for my test project and all the DLL's are there as well as SQLite.Interop.dll
in ./x86/
and ./x64/
我为我的测试项目检查项目 output 并且所有 DLL 都在那里以及
SQLite.Interop.dll
在./x86/
和./x64/
By the way my main project, I am using Microsoft.Data.Sqlite and am targeting net40
, net461
, and netstandard20
顺便说一句,我的主要项目是 Microsoft.Data.Sqlite 并针对
net40
、 net461
和netstandard20
The issue appears to be with how xunit shadow copy feature and how SQLitePCLRaw dynamically loads the SQLite.Interop.dll
When the test run xunit creates a shaddow copy of all the DLL's and places each of them in a separate randomly generated temporary folder ie C:\Users\Administrator\AppData\Local\Temp\4c30a280-0900-4002-874b-a65591ef7c9e\4c30a280-0900-4002-874b-a65591ef7c9e\assembly\dl3\11289531\10e73523_73aed201\Some.dll
The issue appears to be with how xunit shadow copy feature and how SQLitePCLRaw dynamically loads the
SQLite.Interop.dll
When the test run xunit creates a shaddow copy of all the DLL's and places each of them in a separate randomly generated temporary folder ie C:\Users\Administrator\AppData\Local\Temp\4c30a280-0900-4002-874b-a65591ef7c9e\4c30a280-0900-4002-874b-a65591ef7c9e\assembly\dl3\11289531\10e73523_73aed201\Some.dll
When SqlitePCLRaw goes to find SQLite.interop.dll
at runtime it looks inside the shadow copy folder instead of its original location.当 SqlitePCLRaw 在运行时查找
SQLite.interop.dll
时,它会查看卷影副本文件夹而不是其原始位置。
The solution to this is to create a file xunit.runner.json
in your test project and add it to your test project setting its build property to Content
and setting CopyToOutputDirectory to PreserveNewest
解决方案是在您的测试项目中创建一个文件
xunit.runner.json
并将其添加到您的测试项目中,将其构建属性设置为Content
并将 CopyToOutputDirectory 设置为PreserveNewest
Alternatively, if you are multi-targeting and only want to disable shadow copy for net461
you can add the following to your test project file或者,如果您是多目标并且只想禁用
net461
的卷影复制,您可以将以下内容添加到您的测试项目文件中
<ItemGroup Condition="$(TargetFramework) == 'net461'">
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.