PackageReference not supported, plenty more issues.

jonyadamit's Avatar

jonyadamit

19 Dec, 2017 12:56 PM

Hi,
Some of my projects use PostSharp.Patterns.Caching.
This assembly depends on System.Collections.Immutable which in turn depends on .NET Standard.
These dependencies threw me into a DLL hell which I'm fighting with for a couple of weeks (managed to get around it at some point, and it was messed up again later..)

An example issue for this DLL hell:

6>  C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099: Unhandled exception (postsharp-net40-x86-srv.exe release | .NET Framework 4.7.1): PostSharp.Sdk.CodeModel.BindingException: Ambiguous assembly binding policies: Assembly 'system.runtime.serialization.primitives, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a' redirects both to 'system.runtime.serialization.primitives, version=4.2.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a' and 'system.runtime.serialization.primitives, version=4.1.3.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a'.
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.AssemblyBindingPolicyManager.EvaluatePolicy(IAssemblyName assemblyName, Boolean evaluateSystemPolicies)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.CompareExtensions.^4+F3cylo(IAssemblyName _0, IAssemblyName _1, AssemblyBindingPolicyManager _2, BindingOptions _3, Boolean _4)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.ModuleDeclaration.FindAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at ^XJbqCOExOmCj.^COARuyiS(TypeDefDeclaration _0, ModuleDeclaration _1, BindingOptions _2)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.TypeDefDeclaration.Translate(ModuleDeclaration targetModule)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.TypeRefDeclaration.Translate(ModuleDeclaration targetModule)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.TypeRefDeclaration.^gq20Za8my5ww(ModuleDeclaration _0)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.TypeSignatures.GenericTypeInstanceTypeSignature.Translate(ModuleDeclaration targetModule)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.TypeSignature.^gq20Za8my5ww(ModuleDeclaration _0)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at ^XJbqCOExOmCj.^XcvzGbeU(IMethodSignature _0, ModuleDeclaration _1)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.CodeModel.MethodRefDeclaration.GetMethodDefinition(BindingOptions bindingOptions)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.Extensibility.Tasks.IndexGenericInstancesTask.Execute()
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Sdk.Extensibility.Project.Execute()
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
6>C:\src\packages\PostSharp\build\PostSharp.targets(314,5): error PS0099:    at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation).

I should be able to fix these issues by following these guidelines.
PostSharp documentation suggests PackageReference is supported, yet when I create a project that uses PackageReference, and add PostSharp, the project compiles regularly without PostSharp. The PostSharp tab in Project Properties says PostSharp is not enabled for this project.
I can enable it by adding <Import Project="..\packages\PostSharp.5.0.41\build\PostSharp.props" Condition="Exists('..\packages\PostSharp.5.0.41\build\PostSharp.props')" /> to the top of the project file and <Import Project="..\packages\PostSharp.5.0.41\build\PostSharp.targets" Condition="Exists('..\packages\PostSharp.5.0.41\build\PostSharp.targets')" /> to the bottom of the file.
But I must be missing something because the documentation doesn't mention this, and the dependency on the Nuget script was removed by you as far as I know.

What am I missing? Is PackageReference supported by PostSharp? Should I add PostSharp manually to the project file?

Please note that I am following those guidelines since nothing else I've tried allowed me to compile my project again: I have tried all combinations of AutoGenerateBindingRedirects, PostSharpDisableSystemBindingPolicies, PostSharpDisableDefaultBindingRedirects, and manual binding redirects in App.config.
I even moved to using Paket to no avail.
The issues existed when I targeted .NET 4.6.1, 4.7 and now 4.7.1. I hope that after all my projects follow those mentioned guidelines, the issues will be resolved.

Thanks in advance, Jonathan.

  1. 1 Posted by jonyadamit on 19 Dec, 2017 02:00 PM

    jonyadamit's Avatar

    Oh, adding it manually can't be the answer (would require updating manually with each upgrade...)
    So I must be missing something.

  2. Support Staff 2 Posted by PostSharp Techn... on 19 Dec, 2017 03:03 PM

    PostSharp Technologies's Avatar

    Hello,

    we have released pre-release version of PostSharp 5.1, which should handle a lot of issues with assembly loading. We needed to do a lot of breaking changes so it will not be released as a bugfix of PostSharp 5.0.

    Could you please try PostSharp 5.1.1 and let us know whether it helped your case?

    Thanks a lot!

    All the best,
    Daniel

  3. 3 Posted by jonyadamit on 20 Dec, 2017 08:10 AM

    jonyadamit's Avatar

    Hi, Thank you for the swift reply!
    Apparently the specific project I had problems running PostSharp had a <SkipPostSharp> tag, but I missed it since it was buried somewhere in the middle and the PostSharp UI wasn't working so it was hard to find this out.
    I have followed the .NET Standard team's suggestions - converted all my projects to use PackageReference while adding <AutoGenerateBindingRedirects> and all problems disappeared, without having to install the preview release!

    Thanks again, Jonathan.

  4. jonyadamit closed this discussion on 20 Dec, 2017 08:12 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac