Why is there a broken reference to NETStandard when I add a new class library?

EasyGoingPatEasyGoingPat GBMember ✭✭✭

I have just added a new .NETStandard class library to my Xamarin.Forms solution. To do this, I right-clicked the solution, selected New Project | .NET Standard | Class Library (.NET Standard).

This adds the new library but it has a broken reference to Dependencies | SDK | NETStandard.Library.

This seems odd. Am I missing something obvious? How do I fix this?

Sorry for the simple nature of this question but I am nervous about continuing without fully understanding what is going on here, as I've never targeted .NETStandard before.

Kind wishes ~ Patrick

Best Answer

  • EasyGoingPatEasyGoingPat GB ✭✭✭
    edited July 2018 Accepted Answer

    I have fixed this. There seemed to be two problems.

    The first problem is that I found the following two lines in my iOS.csproj file:

      <Import Project="..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props')" />
      <Import Project="..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props')" />
    

    Deleting the obsolete second line got things building but I still could not deploy, even to a simulator.

    I'm not so sure of my solution to the second problem. The problem appeared to be caused by the fact that the shared NETStandard library I added to my project had the same name as the root namespace for the project. For example, assume the parts of my project were named like this:

    MyProject.Android
    MyProject.iOS
    MyProject.Forms

    I tried to call my new shared library MyProject. This gave the error beginning 'The root assembly...' which I show elsewhere in this thread. Renaming my new shared library as MyProject.Core got things working.

    I'd still appreciate comment on this, especially from a Xamarin engineer, because if this is a limitation, it really should be documented somewhere.

    • Patrick

Answers

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭
    edited July 2018

    Try create New Cross-Platform Project and choose NET Standard. Then Add one by one your page from old project and install all plugin from Nuget. it's take some time
    This will help you have a clear new project!

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @Liêm_Nguyễn

    Thank you for your answer.

    Unfortunately, your suggestion is precisely what I am already halfway through doing. I created a new Cross Platform application and chose .NET Standard as the code-sharing strategy. My Xamarin.Forms project has a reference to .NET Standard that is perfectly okay but this latest new library has a broken reference.

    I'm not sure how to fix it because .NET Standard doesn't seem to be in the place you would normally go for different versions of the .NET framework (on my machine C:\Windows\Microsoft.NET\Framework.

    • Patrick
  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
    edited July 2018

    I have just added this library again to my project by right-clicking Solution | Add | New Project | .Net Standard | Class Library (.NET Standard).

    Mysteriously, this no longer shows a broken dependency to NetStandard.Library and I can build this class library independently. However, when I add a reference to it to the iOS project and try to build that, I get the following error:

    The root assembly /Users/*/Library/Caches/Xamarin/mtbs/builds/Serenocalm.iOS/d5560b7d18d94796cc9d6ebafa6342d7/bin/iPhone/Debug/Serenocalm.exe conflicts with another assembly (/Users/*/Library/Caches/Xamarin/mtbs/builds/Serenocalm.iOS/d5560b7d18d94796cc9d6ebafa6342d7/bin/iPhone/Debug/Serenocalm.dll).    Serenocalm.iOS
    

    Does anyone know how I fix this?

    If anyone on Xamarin reads this, I'm really struggling to stay with Xamarin here. I used it almost from the word go, when it involved paying a hefty licence. It was buggy because it was new but support was excellent and I battled through the errors one by one. I thought coming back to it now would be a breath of fresh air. I thought it would feel mature and most things would simply work. Sadly, this has not been experience. It seems harder now than two years ago. This current problem is a perfect example. It seems ridiculous. I created a brand new Xamarin.Forms Solution using NET Standard as the code sharing strategy and now I have tried to add my first class library and I'm completely stuck with the above error. How can such a simple and common task be broken?

    If I don't produce working code soon, people are going to start questioning my choice of technology. Please Xamarin do something to restore my faith.

    • Patrick

      :/

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
    edited July 2018 Accepted Answer

    I have fixed this. There seemed to be two problems.

    The first problem is that I found the following two lines in my iOS.csproj file:

      <Import Project="..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props')" />
      <Import Project="..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props')" />
    

    Deleting the obsolete second line got things building but I still could not deploy, even to a simulator.

    I'm not so sure of my solution to the second problem. The problem appeared to be caused by the fact that the shared NETStandard library I added to my project had the same name as the root namespace for the project. For example, assume the parts of my project were named like this:

    MyProject.Android
    MyProject.iOS
    MyProject.Forms

    I tried to call my new shared library MyProject. This gave the error beginning 'The root assembly...' which I show elsewhere in this thread. Renaming my new shared library as MyProject.Core got things working.

    I'd still appreciate comment on this, especially from a Xamarin engineer, because if this is a limitation, it really should be documented somewhere.

    • Patrick
  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    @EasyGoingPat said:
    I have fixed this. There seemed to be two problems.

    The first problem is that I found the following two lines in my iOS.csproj file:

      <Import Project="..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.3.1.0.637273\build\netstandard2.0\Xamarin.Forms.props')" />
      <Import Project="..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props" Condition="Exists('..\..\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.props')" />
    

    Deleting the obsolete second line got things building but I still could not deploy, even to a simulator.

    I'm not so sure of my solution to the second problem. The problem appeared to be caused by the fact that the shared NETStandard library I added to my project had the same name as the root namespace for the project. For example, assume the parts of my project were named like this:

    MyProject.Android
    MyProject.iOS
    MyProject.Forms

    I tried to call my new shared library MyProject. This gave the error beginning 'The root assembly...' which I show elsewhere in this thread. Renaming my new shared library as MyProject.Core got things working.

    I'd still appreciate comment on this, especially from a Xamarin engineer, because if this is a limitation, it really should be documented somewhere.

    • Patrick

    Thank!. It's helpful for anyone have same issues with you!

Sign In or Register to comment.