Visual Studio 2015 - C# Windows Universal App missing assembly reference
Asked Answered
K

4

9

Today I cloned my windows universal app project from github onto a new machine running a new install of Visual Studio 2015.

After the project loaded, I noticed that all of my pages and properties were underlined red with many errors

CS0246 C# The type or namespace name "<name>" could not be found (are you missing a using directive or an assembly reference?)

as well as others such as

CS0518 C# Predefined type 'System.Void' is not defined or imported

CS0012 C# The type '' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

CS1545 C# Property, indexer, or event 'Application.Suspending' is not supported by the language; try directly calling accessor methods 'Application.add_Suspending(SuspendingEventHandler)' or 'Application.remove_Suspending(EventRegistrationToken)'

I noted that CS0012 actually gives information about what is needed to address the issue:

You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Looking in my project.json file, however, I could see

"dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
}

As a result the project will not build or run, just lists lots of errors, how can you fix this?

Kyte answered 16/9, 2015 at 11:41 Comment(0)
K
24

Looking in the References of the project in the Solution Explorer it can be seen that even though Microsoft.NETCore.UniversalWindowsPlatformis listed as a dependency, it's missing from the project and this is causing the issue.

Visual studio knows that the assembly is a dependency and needs to be referenced but it doesn't seem to come preinstalled with Visual Studio 2015, even when you install all of the Windows 10 development tools during setup, and it doesn't seem to autofetch the package even when it knows it needs it!

To fix, you need to manually install the package using NuGet and it will then be resolved correctly as a reference.

To do this, right click on References, then click Manage NuGet Packages....

On the NuGet Package Manager screen, search for Microsoft.NETCore.UniversalWindowsPlatform and it will be an exact match.

Click on Install in the details pane on the right hand side and Visual Studio will fetch the package and include it as a reference in your project

The red underlining will then all disappear and you can continue working on your project!

Kyte answered 16/9, 2015 at 11:41 Comment(5)
In my case, the reference to "Microsoft.NETCore.UniversalWindowsPlatform" was missing causing many compile errors. NuGet said it was installed already. The fix was to uninstall and then re-do the install. This was from a project from the UWP samples.Unstriped
Also worked for me. Wasn't an immediate return, I had to restart VS2015, but it did solve the issue.Homologize
Thank you! This fixed my issues as well.Approbate
So this is the workaround - is there an actual fix? As in, to prevent this from occurring again in the future?Uyekawa
Thank you. This helped also on vs2017! Just a litle more fyi: CLEAR the NuGet cache before re-install.Giorgia
S
1

I had similar problem. universal project I create my self had reference there. Some of the samples for windows iot sites didn't have reference when downloaded. NUGET said it was already installed. for me the solution was to build the solution and it repaired itself.

Swinney answered 14/1, 2016 at 0:59 Comment(0)
I
0

what worked for me was Tools -> nuget package Manager -> manage nuget packages for solution and update the packages for the solution it adds a lot of stuff and then updates your solution hope it works for you

Inurn answered 4/11, 2016 at 6:8 Comment(0)
H
-1

Have you installed the SDKs? Its possible that it cant find the files assosiated with the references.

windows 10 sdk

windows 8.1 sdk

Hash answered 16/9, 2015 at 13:0 Comment(3)
Yes everything is installed, my answer below is correct; I had a friend who got caught out by this and I saw it for the first time today so decided to do the Q & A to help people out googling the issue in case it helps themKyte
Do me a favor and change your Debugger to x86 or x64 I had a same problem it couldn't find the references after TFS pull because target was Any CPU.Hash
For me the CPU always defaults to ARM on a universal project. Windows Universal SDK tools were updated to v1.1 today which may fix the issueKyte

© 2022 - 2024 — McMap. All rights reserved.