Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands: WACK binary analyzer fails when adding EF Core in UWP class library #5069

Closed
davesmits opened this issue Apr 14, 2016 · 29 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@davesmits
Copy link

I am using Entity Framework core in my UWP. But since that wack fails with lot of errors but mainly because this:

File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\coreclr.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\dbgshim.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\mscordaccore.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\mscordbi.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the DBCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the NXCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.46.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the SafeSEHCheck check.

this blocks me to get the app in the store. As soon i remove the EF pacakges the errors are gone. Any known issues on this or know how to fix this?

@rowanmiller
Copy link
Contributor

@davesmits what version of EF Core are you using (RC1 or the nightly RC2 builds)?

@davesmits
Copy link
Author

davesmits commented Apr 19, 2016

RC1. tried to get RC2 from myget but nuget refused to install that package

@rowanmiller

nuget error to include that package:
System.Reflection.Primitives 4.0.1-rc2-23931 provides a compile-time reference assembly for System.Reflection.Primitives on UAP,Version=v10.0, but there is no run-time assembly compatible with win10-arm.

or do i also have to use the updated .net core packages?

@davesmits
Copy link
Author

i just updated everything to the rc2 version from myget (included .netcore) and now when building a release build it returns very quickly this error:

Severity Code Description Project File Line Suppression State
Error Loading assembly "C:\Users\dave.nuget\packages\runtime.win7-x86.Microsoft.NETCore.Runtime.CoreCLR\1.0.2-rc2-24008\runtimes\win7-x86\native\mscorlib.ni.dll" failed. System.TypeLoadException: Could not load type 'System.Object' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element)
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadAssemblyResources(String name, String outFileOrDir) XpertFinder

@rowanmiller
Copy link
Contributor

@davesmits yeah RC2 won't work with .NET Native until some new UWP is made public - the .NET Native team has some new work coming that helps solve a lot of the .NET Native issues that we had in RC1.

We've assigned this to someone to investigate since we haven't seen these particular failures before and want to make sure they won't carry over into future releases.

@natemcmaster
Copy link
Contributor

Actually, this UWP tooling just released publically last week. It's a little hard to see, but you need to have .NET Native SDK 1.3.1 installed and use Microsoft.NetCore.UniversalWindowsPlatform 5.1.0. Also, make sure you are building with "Compile with .NET Native tool chain" enabled (on by default in "Release" mode.)

The release was announced here: https://blogs.msdn.microsoft.com/visualstudio/2016/04/11/whats-new-in-vs-2015-update-2-for-universal-windows-developers/

@davesmits
Copy link
Author

i did this with the 1.3.1 release; before that release the number of generics EF core used let the compiler go out of memory. .net native feedback alias helped me to figure that out. If using .net core 5.1 EF RC2 doesnt want to install and with the RC1 having those errors as mentioned on top

@natemcmaster
Copy link
Contributor

@davesmits can you share your project.json and project.lock.json?

@davesmits
Copy link
Author

@natemcmaster when using .netcore 5.1 and rc 1?

@natemcmaster
Copy link
Contributor

Ms.NetCore.Uwp 5.1 and RC2. These should work, which is why I'm asking. If they don't, then we need to re-open #4802

@davesmits
Copy link
Author

which myget url i can best use? i am now using https://www.myget.org/F/aspnetcirelease/api/v3/index.json (changed it this evening) and the EF library is now 7.0.0.0-RC1-update1

@natemcmaster
Copy link
Contributor

I'd recommend https://www.myget.org/F/aspnetrelease/api/v3/index.json. It's been through testing. https://github.com/aspnet/Home/wiki/NuGet-feeds

Here is my project.json

{
  "dependencies": {
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0-rc2-20581",
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
  },
  "frameworks": {
    "uap10.0": {}
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

@davesmits
Copy link
Author

if i add via the nuget UI i get this error: Package restore completed successfully for 'XpertFinder.Model'.
Unable to find metadata of Microsoft.Data.Sqlite.1.0.0-rc3-20550 ; when i manually edit the project.json it works. i am now building the release build and wil lrun wack one more time

@davesmits
Copy link
Author

the binary analyzer of wacks returns less faults.. but still some:

File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.51.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the AppContainerCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.51.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the DBCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.51.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the NXCheck check.
◦File C:\Program Files\WindowsApps\SparkedApps.XpertFinder_2.1.51.0_x86__pkpvvn6f26pj6\sqlite3.dll has failed the SafeSEHCheck check.

@natemcmaster
Copy link
Contributor

I just tried using the WACK on a UWP app with EF RC2, compiled in release mode. Everything passed for me (except the branding...guess it didn't like my logos). http://bl.ocks.org/natemcmaster/raw/aee79d6c21abd5413ab7607f80552bc0/

@davesmits
Copy link
Author

davesmits commented Apr 22, 2016

I found the situation where it goes wrong. If you create a class library and reference emtityframework.sqlite and entityframework.commands in that class library, then from your app reference to that class library you will get errors. i added a sample where i have 2 empty projects and getting this error

Test.zip

And to clarify this. in my app i have 3 projects:

  • the app
  • winmd for background task
  • class library to share code between the winmd and the app

@Cologler
Copy link

I got same issue on my app. I think Microsoft.Data.Sqlite using wrong sqlite3.dll (replace with sqlite3.dll which from SQLite for UAP will be fine).

Also include some API test failed:

此应用程序类型不支持 kernel32.dll 中的 API AreFileApisANSI。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API CreateFileA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API CreateFileMappingA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API CreateFileMappingW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API CreateFileW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetDiskFreeSpaceA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetDiskFreeSpaceW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetFileAttributesA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetFileAttributesW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetFileSize。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetFullPathNameA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetModuleHandleA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetTempPathA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetTickCount。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetVersionExA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API GetVersionExW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API HeapValidate。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API LoadLibraryA。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API LoadLibraryW。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API LocalFree。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API LockFile。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API MapViewOfFile。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API SetFilePointer。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API TlsGetValue。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API UnlockFile。sqlite3.dll 调用此 API。
此应用程序类型不支持 kernel32.dll 中的 API VirtualProtect。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API __dllonexit。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API __mb_cur_max。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _beginthreadex。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _endthreadex。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _errno。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _iob。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _isctype。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _pctype。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API _winmajor。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API abort。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API calloc。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API fflush。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API free。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API fwrite。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API localeconv。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API localtime。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API log。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API malloc。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API memcmp。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API memmove。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API memset。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API qsort。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API realloc。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API strcmp。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API strncmp。sqlite3.dll 调用此 API。
此应用程序类型不支持 msvcrt.dll 中的 API vfprintf。sqlite3.dll 调用此 API。

@natemcmaster
Copy link
Contributor

I believe what is happening here is a limitation in the workaround Microsoft.Data.Sqlite has to ensure your project gets the right version of sqlite3.dll. For now, manually replacing sqlite3.dll with a UWP compatibile version is the best workaround.

Explanation:
NuGet does not support any features to distinguish between native libraries compiled for WinRT vs Win32. By default, NuGet will try to use sqlite3.dll compiled for Win32 APIs (the source of the kernel32.dll and msvcrt.dll errors). Microsoft.Data.Sqlite tries to fix this with a little bit of MSBuild magic (see build/netcore50/Microsoft.Data.Sqlite.targets). Despite this, it appears something in NuGet/MSBuild isn't getting the right version of sqlite3.dll into the build output when Microsoft.Data.Sqlite is in a class library, not the UWP app itself. We'll need to go spelunking in MSBuild to figure out why.

@davesmits
Copy link
Author

davesmits commented Apr 29, 2016

any hints how to do? i tried to add sqlite extension to my project but that gives error about a double file as payload. Also tried to remove the sqlite3.dll as post build action in my class library and then add the file again but so far no real luck :(

i just tried this in the app project as post build action:
copy /Y "C:\Program Files (x86)\Microsoft SDKs\UAP\v0.8.0.0\ExtensionSDKs\SQLite.UWP.2015\3.12.2\Redist\Retail\x86\sqlite3.dll" "$(ProjectDir)$(OutDir)sqlite3.dll"

But it didn't really fix the problem. coreclr is still dragged for instance...

to be honest. this limitions is making EF useless for any serious app.. Background Tasks are very important part of apps and force developers to use this kind of structure.

@Cologler
Copy link

Cologler commented Apr 29, 2016

So I use sqlite.net-pcl now, everything fine...... o(^_^)o

@natemcmaster
Copy link
Contributor

I confirmed the issue, but the issue is not in EF. The issue is in how Microsoft.Data.Sqlite is packaged. The workaround is to add Microsoft.Data.Sqlite as direct dependency of your app. When it is brought in as a transitive dependency, NuGet gets the wrong native binaries.

Moving to aspnet/Microsoft.Data.Sqlite#245

@natemcmaster
Copy link
Contributor

natemcmaster commented May 3, 2016

Found that this is actually 2 issues. First the sqlite3.dll issue aspnet/Microsoft.Data.Sqlite#245.

Second issue: Microsoft.EntityFrameworkCore.Tools (called EntityFramework.Commands in RC1) brings in the CLR when this is listed as a dependency of a class library that is used in UWP.

Reason

This package uses MSBuild to do some funky dll swapping in order to enable package manager console commands. This MSBuild logic looks for "UseDotNetToolchain" to determine whether to do this swapping or not. Class libraries never have UseDotNetToolchain set to true, even in release mode, so our MSBuild script is incorrectly putting the wrong Microsoft.EFCore.Tools dll into output.

Workaround

  • Put the dependency on Ms.EfCore.Tools in the application project, not the class library
  • Or, when preparing to release, remove this dependency. It is only needed for package manager console commands, and is not necessary for the app to execute correctly.

@natemcmaster natemcmaster changed the title WACK -> Binary analyzer test fails when adding EF Core in UWP Commands: WACK binary analyzer fails when adding EF Core in UWP class library May 3, 2016
@natemcmaster
Copy link
Contributor

cc @rowanmiller @divega this limitation is going to affect RC2 release

@divega
Copy link
Contributor

divega commented May 3, 2016

I believe the workarounds are acceptable for RC2, but we need to mention them in any relevant documentation and release notes.

@rowanmiller
Copy link
Contributor

@natemcmaster can you make sure this gets added to the list of known issues in our docs

@natemcmaster
Copy link
Contributor

Closing to consolidate bugs. This is essential the same issue as #3682. I'll add this scenario to that issue.

@natemcmaster
Copy link
Contributor

Fixed in #5474

@Herdo
Copy link

Herdo commented Jun 13, 2016

@natemcmaster Can we expect to see the fix in the 1.0.0 milestone (27th June 2016)?
See #245 of Microsoft.Data.Sqlite

@natemcmaster
Copy link
Contributor

@Herdo Yes, the fix for this issue and aspnet/Microsoft.Data.Sqlite#245 will be in the next release. If you want to try out the fixes early, you are welcome to use our nightly feeds.

@Herdo
Copy link

Herdo commented Jun 14, 2016

@natemcmaster Thanks for the info! I'll be patient and use the workaround while waiting 12 more days.
Excited for the new release!

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

7 participants