oysteinkrog / SQLite.Net-PCL

Simple, powerful, cross-platform SQLite client and ORM - Updated version with PCL support
MIT License
353 stars 162 forks source link

JetBrains.Annotations dependency problem #170

Closed Aurora12 closed 9 years ago

Aurora12 commented 9 years ago

I'm using the latest SQLite.Net.Async PCL 3.0.4-beta in my Universal Store Project. Works fine when built for WP8.1, but gets me an error (below) when built for Windows 8.1. The error is thrown on the first CreateTableAsync() call.

The package installs JetBrains.Annotations 9.1.1 dependency which gets you a reference to JetBrains.Annotations.PCL1.dll in desktop part of the project. (While when installing for Windows Phone part, it gets you a reference to JetBrains.Annotations.PCL328.dll.)

When I launch desktop version:

Could not load file or assembly 'JetBrains.Annotations.PCL328, Version=8.0.5.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325' or one of its dependencies. The system cannot find the file specified.
   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(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
   at System.Attribute.InternalGetAttributeUsage(Type type)
   at System.Attribute.InternalIsDefined(PropertyInfo element, Type attributeType, Boolean inherit)
   at System.Attribute.IsDefined(MemberInfo element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.IsDefined(MemberInfo element, Type attributeType, Boolean inherit)
   at SQLite.Net.TableMapping..ctor(Type type, IEnumerable`1 properties, CreateFlags createFlags)
   at SQLite.Net.SQLiteConnection.CreateAndSetMapping(Type type, CreateFlags createFlags, IDictionary`2 mapTable)
   at SQLite.Net.SQLiteConnection.GetMapping(Type type, CreateFlags createFlags)
   at SQLite.Net.SQLiteConnection.CreateTable(Type ty, CreateFlags createFlags)
   at SQLite.Net.Async.SQLiteAsyncConnection.<>c__DisplayClass11_0.<CreateTablesAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

So, it looks like the reference is wrong or something... Is ReSharper annotations dependency even needed there?

oysteinkrog commented 9 years ago

Hmm, that's a scenario I have not thought about, I suppose it's really a general problem with using nugets? What happens if you manually reference the 328 (PCL) version in both projects?

animaonline commented 9 years ago

I'm getting the same error, could you remove the JetBrains reference, please?

citizenmatt commented 9 years ago

This seems to have been built against JetBrains.Annotations 8.0.5, but the package includes 9.1.1. Something's gone a little wrong - I'd suggest rebuilding the dll in the SQLite package. The 9.1.1 annotation dlls contain a bunch of attributes that are all marked with [Conditional("JETBRAINS_ANNOTATIONS")] (I suspect this wasn't in 8.0.5). Unless you define JETBRAINS_ANNOTATIONS when building the SQLite dll, the annotations don't get compiled in - so under normal use, the SQLite dll will have no binary reference to JetBrains.Annotations at all, and you won't need the reference to JetBrains.Annotations 9.1.1 in the package, either (you could mark it as a developer dependency in the SQLite's packages.confis).

The downside to doing this is that consumers of the assembly don't get the benefits of attributes - they're only useful when editing the source of the SQLite library. If you'd like consumers of your library to get use out of the annotations, you should remove the reference to the JetBrains.Annotations package, and instead include the source for the annotations directly in your project. You can get the source from ReSharper → Options → Code Annotations. ReSharper 9.1 allows you to get the source where all the annotations are marked as internal. This is highly recommended, as it prevents the annotation attributes being visible to the consumers of your dll (but the attributes are still visible to, and used by, ReSharper).

Hope this helps.

oysteinkrog commented 9 years ago

@citizenmatt Ok, I will try that, thanks for the help:)

Aurora12 commented 9 years ago

@oysteinkrog Seems to work fine after I manually replace JetBrains.Annotations.PCL1.dll reference with JetBrains.Annotations.PCL328.dll. I'm not sure why the wrong library gets referenced during installation, but this is a stable behaviour.

http://gyazo.com/75359c1980dea04142f2b8fbcb615f60

oysteinkrog commented 9 years ago

Hmm ok, well IMO this seems like a general nuget problem to me. I will do as suggested and bundle the annotations inside the project instead. I had hoped to avoid this but it seems I have little choice. By doing so there will be no external dependecies. I'll try to get to it this evening or during the weekend.

Aurora12 commented 9 years ago

Thanks for your work, much appreciated! @oysteinkrog