You must add a reference to assembly

When I try to build my MonoDroid project, I get following errors:

Error 1 The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Error 2 The type 'System.Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Can you please help me with this?

Posts

  • DespotDespot RSMember

    Just to add that this is a problem that occurs when I try to reference object from Portable Class Library

  • MarkDownesMarkDownes USUniversity ✭✭

    Did you find a solution to this problem?

  • CheesebaronCheesebaron DKInsider, University mod

    This problem was solved long ago. However, I've seen some people having troubles with this again in Visual Studio 2015. What is your environment like @MarkDownes?

  • MarkDownesMarkDownes USUniversity ✭✭

    I'm trying to bind to a native Java .jar and when I compile the binding project I get the following exception: Error 74 The type 'System.Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
    Apparently one of the auto-generated types contains an Enum. When I go to Add Reference System.Runtime is not available.

  • ravensorbravensorb USMember ✭✭

    Any update to this? I am having this issue with VS2015 RC on Windows 10 Enterprise

  • Problem here too! VS 2015 RTM and Windows 10 RTM

  • amirjalaliamirjalali USMember

    I have the same problem vs 2015 RTM

  • FabioGFabioG ITBeta, University ✭✭✭
    edited July 2015

    Same problem here (VS 2015, Xamarin.Forms project on Android). Can we get a solution to this issue or at least a workaround?

  • pedroccrlpedroccrl BRMember

    Same problem here. VS2015 Native Portable Project

  • LarsPerssonLarsPersson SEMember ✭✭
    edited August 2015

    Just installed VS2015 got 2000 errors with the "The type'...' is defined in an assembly that is not referenced"...
    using Win 7.

  • LarsPerssonLarsPersson SEMember ✭✭

    Also when I later tryied to use VS2013 again all the Xamarin projects were incompatible. To solve that i had to right click Xamarin in Add/Remove program and select Change. Then i could install Xamarin for vs2013 again. Just downloading and installing the normal way did not help.

  • OliverMelcherOliverMelcher DEMember ✭✭

    Same here :-/ with VS 2015. Same solution in VS 2013 works fine.
    Strange: I saw that the Errors only come from the IntelliSense...when i comile the solution, the are no build erros

  • tanushstanushs USMember

    @OliverMelcher exactly what I'm facing.

  • OliverMelcherOliverMelcher DEMember ✭✭

    For me it happens in the combination: Xamarin (Android) Project with a references to a PCLs (all with target profile 111: .NET Framework 4.5, Windows 8, Windows Phone 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS (Classic) )

    Using the same PCLs in a "non Xamarin" project (e.g. WinForms) works fine...no IntelliSense errors.

  • FabioGFabioG ITBeta, University ✭✭✭

    In my case the solution doesn't compile at all. If I open the very same solution with Xamarin Studio on a Mac, it works just fine.

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    @OliverMelcher
    Your solution solved my problem. Thank you for posting what worked for you. You saved me a ton of time.

  • OliverMelcherOliverMelcher DEMember ✭✭

    @KevinFord I'm happy to hear that.

    But: Since it seems to be only an IntelliSense problem, it's a workaround with a bad taste. Because the added references aren't really necessary...

    It would be nice to get an official statement to this.
    Hello, Xamarin-Team...?

  • OskarEmilSkeideOskarEmilSkeide USMember
    edited August 2015

    I have the same problem, VS2015 and Windows 10. I agree with @OliverMelcher, adding "dummy" references should only be considered as an emergency band-aid, not a workaround.

    EDIT: This worked for me, for some reason I had to restart Visual Studio twice to get rit of the errors. https://bugzilla.xamarin.com/show_bug.cgi?id=32622

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    @OliverMelcher
    My experience leads me to believe that this will be fixed by the Xamarin team so I'm not overly worried about that. Until then it is just a bit of a PITA and your workaround has probably saved a lot of us significant headaches.

  • CheesebaronCheesebaron DKInsider, University mod

    When building in VS2015, in the dropdown box down in the Error List window where it says Build + Intellisense switch it over to Build Only and see the errors disappear and you are able to build again.

  • TimothyLeeRussellTimothyLeeRussell USMember ✭✭

    @OliverMelcher - thanks. Adding reference hints fixed the intellisense errors for me as well.

  • C0D3NameC0D3Name USUniversity ✭✭✭

    I had a similar error when attempting to leverage MvvmCross in VS2015, my issue was with the System.Linq.Extensions library not being properly referenced, in addition to IntelliSense incorrectly flagging System.Runtime as a missing reference. All projects built fine using Xamarin Studio in Win and Mac; actually, although there were IntelliSense errors in VS2015, the project was able to build so long as I didn't try to resolve any of the missing references.

    When building in VS2015, in the dropdown box down in the Error List window where it says Build + Intellisense switch it over to Build Only and see the errors disappear and you are able to build again.

    Thanks Tomasz, this fixed my environment. Looks like there is an issue with VS2015 IntelliSense being able to correctly map the Xamarin implementation.

  • @OliverMelcher - Thanks!

  • MatheusGuimaraesMatheusGuimaraes GBMember, University ✭✭

    @OliverMelcher , that's perfect, thanks! The most important message though I think is that this is JUST AN INTELLISENSE problem (well and a Visual Studio UI problem since even on the References folder it shows a little warning sign and the properties for those files are missing information).

    If you ignore it and build the project it should still work.

    Having said that, it's really bad that you can't trust build error messages and the advice to devs is just "ignore it". This makes Xamarin look like a broken immature product so it should be really high in the Xam team bug fixing priority in my opinion.

  • eamreamr USMember

    Ever since upgrading to VS2015 I've been having the same Intellisense issues.

    Recently one of those errors went from fictitious to real and was preventing a build. Following @OliverMelcher solution I was able to get rid of the Intellisense errors and a real problem that was hiding among all those "errors"....

  • MaikeldeLaatMaikeldeLaat NLMember
    edited October 2015

    I am also experiencing build errors. After upgrading to VS.NET 2015 I can still compile my PCL's (Profile111) and some of my Android libraries, despite the IntelliSense errors. However one of my Android projects does not compile. It contains a class that is derived from a class in a PCL library. This class overrides a a method that returns a System.IO.Stream. In my build errors (not IntelliSense!) there is a message saying "The type 'Stream' is defined in an assembly that is not referenced" and also a message "return type must be 'Stream' to match overridden member". Same kind of problems arise with System.Threading.Tasks, etc.

    Anyone found a solution yet?
    EDIT: I solved it by removing my hidden .vs folder (again) and removing references to System.ObjectModel and System.Runtime from the Android project.

  • AngelRAngelR USMember

    Thanks a lot @OliverMelcher . You save me to became crazy !

  • SumitmPathakSumitmPathak USMember ✭✭

    Thanks @OliverMelcher, this solution work for me

  • ccamiloccamilo FIMember

    @OliverMelcher said:
    Today i tried to add the missing reference(s) manually by opening the projects .csproj file in a text editor, since it is not possible to add them via "Add Reference.." (they don't appear in the list but they exist, seems to be a problem with the framework-version-filter!?)

    And voila: everything works fine, no more IntelliSense errors... Project successfully compiled an deployed to device.

    I had to add the following lines, but it depends on what you've referenced in your PCLs

    <Reference Include="System.Runtime" />
    <Reference Include="System.Globalization" />
    <Reference Include="System.ObjectModel" />
    <Reference Include="System.Net.Primitives" />
    

    It is March 2017 and still this tick is needed. Thank you Oliver.

  • yangevanyangevan USUniversity
    edited April 2017

    Thanks a lot @OliverMelcher , it worked for me.

    Error 1 The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

    Steps:
    1.
    Open the .csproj file in a text editor , and add below reference manually.
    <Reference Include="System.Runtime" />

    2.
    Close the project and restart it

  • DeanF.7526DeanF.7526 USUniversity

    Thanks @OliverMelcher ! Worked for iOS binding project in VisualStudio for Mac

  • NiMa.4436NiMa.4436 USMember
    edited June 2017

    I got the same error, and I believe it happend after updating Xamarin Studio and some packages (didn't check which). For me the error pointed to JsonConvert from the Json.NET package. So after reading through this and not liking the workaround I simply removed the Json.Net package from my solution and re-added it.
    This resolved the error for me.

Sign In or Register to comment.