none
.NET Standart 1.2 Exception RRS feed

  • Question

  • I am trying to use a .NET Standard 1.2 library from a Windows Phone 8.1 Project. It Compiles fine but at runtime i get this exception The type 'Dictionary<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. I have checked all my nuget packages and are correct in both projects. Any help appreciated!!!!

    When I call the same code from a WPF application that targets 4.5.1 framework version it executes fine!!!!

    Thank You!!

    Wednesday, February 15, 2017 10:29 PM

Answers

  • Finally I was able to locate the problem. It was a reference in a third party dll (LiteDB.dll) although it is compiled targeting .Net Standard when i removed it my code executed fine!!

    Thank you all for your help!!! I apologize for not investigating deeper!!

    I wish you all happy coding!!

    Friday, February 17, 2017 11:50 AM

All replies

  • Try do "Install-Package System.Collections -Version 4.0.0" in your package manager console to install corresponding System.Collections package.
    Thursday, February 16, 2017 4:03 AM
    Answerer
  • Already did that but it wont install the package. Probably 4.0.0 is not the correct version when targeting .NET Standard 1.2. .Net Standard library uses the 4.0.3 version of System.Collections dll. This is the strange thing ..... why it is trying to use 4.0.0 ???!!!??
    Thursday, February 16, 2017 6:48 AM
  • It try to use 4.0.0 probably because one of the library you're using is referencing it.

    Try to "Debug run" your project and view the Output window, see if it can show you load fail when trying to load what assembly.

    ======

    Btw, I'll try to download the package v4.3.0. Since it does define the target for "netstandard1.0", I think it'll install successfully on your case. See if the library will run System.Collection.dll of a greater version.


    Thursday, February 16, 2017 7:29 AM
    Answerer
  • Hi Alex,

     "You must add a reference to assembly" actually meant, that caller and reference projects didn't  have the same target framework. The caller project had .Net 4.5 , but referenced library had target 4.6.1.

    https://support.microsoft.com/en-us/help/2971005/error-message-when-you-compile-applications-to-target-the-.net-framework-4.5.2

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.




    • Edited by Kristin Xie Friday, February 17, 2017 3:01 AM
    Thursday, February 16, 2017 7:53 AM
  • There is no reference (at least directly on the 4.0.0 version) all other project target .Net Standard 1.2 I have double checked that.

    Also I tried to drop and re install all nuget packages.

    Thursday, February 16, 2017 10:12 AM
  • Hi Kristin,

    Thank you for your message.

    Does .NET Standard 2.0 able to used in windows 8.1 projects??

    If yes how can i make it available in me version of visual studio since now it is not in the drop list of available .Net Standard Versions.

    Thank You.

    Thursday, February 16, 2017 10:17 AM
  • Hi Alex,

    >>Does .NET Standard 2.0 able to used in windows 8.1 projects??

    No, sorry my previous reply may misunderstood you.

    Here is a good picture shows that.

    For more details, you can check https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Kristin Xie Friday, February 17, 2017 3:00 AM
    Friday, February 17, 2017 3:00 AM
  • Hi Kristin,

    I knew that you can't target windows phone 8.1 from .Net Standard 2.0 that's why I asked you!!

    Nevertheless what I tried in order to find a solution to my problem is that I have put the code snippet that throws the exception directly on the phone project to see what exception will be thrown(before the code executed on another dll library). When I executed the code this is what i got :

    Could not load file or assembly 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    code snippet :

     var type = Type.GetType("oda.Repositories.ProductRepository, oda.Repositories, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

     var repository = Activator.CreateInstance(type, null) as IProductRepository; <<<this is where the exception is thrown.>>>

    PS : the same code executes fine when consumed from a wpf desktop application.

    Any help???!!!!

    Friday, February 17, 2017 7:06 AM
  • Hi Alex,

    Based on your scenario, it looks that you want to add more framework in your app.

    I would suggest you have a look at this blog:https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-about/

    If you still have issue, I would suggest you ask in https://forums.asp.net/1255.aspx/1?ASP+NET+Core

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 17, 2017 8:14 AM
  • If you want, please copy your project to a new location, remove everything except the referenced packages, add a new form for starting form, and see if it can compile.

    If you see the problem persists, please upload the that now-dummy project to somewhere for us to download. I'll have a look.



    Friday, February 17, 2017 9:15 AM
    Answerer
  • Finally I was able to locate the problem. It was a reference in a third party dll (LiteDB.dll) although it is compiled targeting .Net Standard when i removed it my code executed fine!!

    Thank you all for your help!!! I apologize for not investigating deeper!!

    I wish you all happy coding!!

    Friday, February 17, 2017 11:50 AM