Reference Missing After Nuget Package Update - c#

I want to start off by saying I've been really hesitant to ask this question because it seems like it should be such a simple thing, however, I've scoured the internet and all I can find is the basic solution to something similar to my issue.
I have a nuget package that is v 1.30 and I'm trying to update it to 1.41. I've used the NuGet UI and I've also used the Package Manager Console to do this multiple times with small variations and I continue to get the same result. After I do something like "Update-Package PackageName" my package updates correctly. NuGet deletes the old reference and the old files and the 1.41 version is referenced by all the projects in the solution using that package. When I look at the Code, there are no syntax errors, Visual Studio seems to think the reference is just fine and I can even ctrl+B (re#er) to 'go to declaration.' However, when I build, every place I have 'using PackageName' in code throws an error that says
"The type or namespace name 'Common' does not exist in the namespace 'PackageName' (are you missing an assembly reference?)"
I have tried cleaning my solution. Then building. I've tried resetting through Git, cleaning the solution, updating then building. I've tried updating, cleaning, deleting the reference, building (will get the errors obviously), then adding the reference back in manually and building. Every time I try I get the same error. It's only happening for my Core project, but all my other projects depend on the Core, so they won't build anyway. I'm assuming this issue would still present itself if they were able to build. I've looked at the properties of the reference, it is referencing the v 1.41 file and it is set to Copy Local = True (I read somewhere someone suggested looking at that).
I'm open to suggetions for things to try. I don't have any code changes that I'll lose of I do a Git Reset, so I can try whatever.
Thanks Internet.

After trying several different things, we figured out it was a version mismatch with ASP.NET. Someone had pulled in a newer package that required updating to ASP.NET 4.5 and the solution I was working in was still ASP.NET 4.0. After updating to 4.5 the problem with the references was resolved. But we ran into some new Automapper issues. One thing after another. However, if you're banging your head against your desk in frustration because of this problem, check the framework version of your projects and the package you're updating.

Related

Could not load information for project X after update codegeneration 6.0.9

I'm developing a .NET Core project. Yesterday, Web.CodeGeneration was updated automatically. After the update, I get an error when I try to add new view to my project:
"Scaffolding Failed"
"Could not load information for project X"
I tried to remove and re-install all nuget packages again, and I checked package versions and all of them are 6.0.9 so, same version.
I tried to create a new project to test "add view", but when I install Entity Framework Core packages with web.codegeneration in the test, project, I again get the same error.
How to fix it?
Unload all your class libraries/other projects except for your web application then try re-adding any scaffolded items. This is the current workaround that works on my end, at least until this bug gets fixed.
Update:
Bug is patched with the Microsoft.VisualStudio.Web.CodeGeneration.Design 6.0.10
EDIT - Fixed in 6.0.10, if you are experiencing this issue make sure you update the packages.
The issue has been reported and is a bug in the scaffolding code.
The suggested workaround is to scaffold in a new solution/project with the same name(s) and then copy the files over:
Make new project with same solution and project name and add DB context and
other necessary thing than scaffold then the new added files add in the
main project you are making, now you are good to go.
Unloading the linked projects as suggested by others works, provided you don't have your models in separate class projects.
Otherwise we will have to wait
Remove all project references in the project you are working on, then you won't get error. After adding Areas etc. you can again add project references
If you create references to other projects, the error returns. Importing the libraries works, but if you reference them it gives an error
This isn't actually an answer, but I'm too new to leave a comment. I just wanted to pass along some information that I found useful.
I was having an issue scaffolding my MVC Controller, with views, when my Library was unloaded, even though I kept the reference. This bug is also being discussed on GitHub, and Deepak Joy Jose uploaded this video showing the workaround: Scaffolding Workaround It's for identity scaffolding issues, but the same logic applies to controllers. It's a long workaround, but it did work for my issue.

Trying to add a reference to my solution

I am a complete stranger to adding "custom" references to my projects, usually everything I need I can find in NuGet packages. Ive come across a problem and the solution I've found is to add the following reference to my project:
https://microsoftdwayneneed.codeplex.com/
Ive downloaded the source code, opened up the project in VS and hit build. I then went into the bin/Release folder and added the .dll for both Win32 and normal which I assume is any CPU.
The problem I faced earlier is now fixed, however now a new problem arised: I keep getting the message that the Microsoft Visual Studio XAML UI Designer has stopped working. The error it gives is a NullReferenceException and in the name is "dwayneneed" so I can only assume that I messed up adding the reference.
Can someone explain to me how to add references like the one above correctly to my solution.
The problem Im trying to solve for those wondering:
https://github.com/MahApps/MahApps.Metro/issues/488
the solution, see: https://github.com/MahApps/MahApps.Metro/wiki/FAQ
Do you mean adding a solution to the solution, like this.

Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute'

I'm trying to run a .NET MVC application on my local computer that I got from GitHub.
When I hit run on Visual Studio, everything complies and a new browser window opens with the error:
CS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute'
The compiler section in the same window, shows the following error:
I've checked on google and this seems to be the same error.
This guy was using a dynamic type himself, on the other hand I'm not using any dynamic type, this is being auto generated by .NET's compiler, and I'm using .net 4.5 which should has support for dynamics.
I tried to apply the same solution (Changing all System.Core references to 4.0)
but the thing is that all of them are version 4.0 already.
Do you have any idea how could I resolve this?
I had a similar error on a project I was trying to migrate. Try re-targeting the framework of the project back a version or two, and once you find a target version where you do not get the error, re-target back to the version you originally had trouble with.
I was getting the same error on a website project targeted for 4.6.2 that was referencing some older libraries, re-targeted it back to 4.5.1 and that resolved the error. I immediately re-targeted back to 4.6.2 and did not encounter the error again.
I had this same issue, but none of the answers here solved it, but did point me in the right direction. I think I didn't update the .NET version on my machine to the newer one. After installing it, I rolled back the targeted framework (as was suggested), retargeted the newer framework, and did a few extra things also:
Reinstalled ALL packages by running this in the package manager:
update-package -reinstall
I also compared my project to one that was working for 4.5 and did this:
Opened my project file and removed all "BCL" related elements.
Uninstalled all "BCL" packages in the NuGet package manager for the project (guess it's not needed moving to 4.5+...?)
Removed an old package version of System.Net.Http, which did not get updated for some reason (see web.config - versions should show oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0").
Have to restart VS.
Rebuild solution.
Error is now gone. ;)
One other thing I did to resolve some other errors was to clear the component cache by deleting all files in here:
C:\Users\{USERNAME}\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache\
[rant] Wasted a whole day with all this. Thanks to MS for stealing one more day of my life fixing senseless issues that should never be. Every time I upgrade I always get a wonderful surprise, and a lovely game of fix the red herring. Would it not hurt to detect these conflicts for those upgrading old projects? Perhaps better error traces when things go wrong? I doubt it would be that difficult. Perhaps even something like AsmSpy, but more advanced, built in to VS? [/rant]
Saw this in VS 2019. I excluded and re-included the problematic file (in my case _Layout.cshtml) and that fixed the problem.
I got this error suddenly a couple days after updating to VS2015.3 using 'traditional' MVC app (not new .NET Core / vNext app).
Turns out this error can be a complete red herring.
Make sure:
You haven't got any other errors at all
You've checked the output window for any errors that don't show in the 'Output' window.
Make sure you don't have any conflicting references
In my case I had a typescript error that was causing an error and for some reason triggering this weird 'red herring' dynamic error too.
My fix was to go into the .csproj file and update the typescript tools version to 1.8 (need to unload project and edit by hand). As I said this is unrelated to the error, but I mention the specifics because someone else may end up with this same problem.
I believe that 1.7 didn't accept 'None' for the typescript module system whereas 1.8 does, hence the error.
Adding a reference to System.Dynamic.Runtime did it for me.
I hesitate to write this as an answer, but for me the error appeared in a .cshtml file. I closed the page, rebuilt, and the error vanished. Always best to try the simple things first.
I had the same error, there were just 2 unused tables of my databaseset that I had to delete. I wonder why it worked when I manually change sth in an auto-generated code work but after deleting, it worked.
So be aware that such inconsistencies can also cause this error.
My solution was to correct the version of MVC in web.config under Views folder. E.g. the project referenced MVC assembly version 5.2.2.0 but in the Views/web.config file was version 5.2.4.0 (see image).
Image
Tried a few other answers with no luck, but the overall consensus appears to be that this some sort of issue with cached build artifacts or compiler state or something. Here's what worked for me:
Delete the problem .cshtml file, watch error disappear
Open source control and revert the deletion
This error will come because of the different versions of your Sitecore.Web.Mvc.Dll in solution reference folder(Project name->References->Sitecore.Web.Mvc->right click and check properties) and the version of Sitecore.Web.Mvc.Dll in Web.Config in views Folder.
For solving this error you have to make sure that the version of Sitecore.Web.Mvc.Dll is same in both folders.
Thanx.
For my case, I fixed to run the command line "update-package -reinstall" on the Package Manager Controler.
My problem was in the _Layout.cshtml.
None of the solutions above did the trick for me. I am using VS2017 for this project, upgraded an ran into the same message.
I had commented out a 2 lines in 1 comment #* *#
My solution was to comment out each line separately. What a mystery!
A few hours lost on this.

When compiling solution, previously working assembly reference / using no longer works [duplicate]

My C# WinForms solution has two projects.
A DLL which is the main project I'm working on, and an executable WinForms I call "Sandbox" so that I can compile/run/debug the DLL easily in one go.
I'm working in .Net 4.0 for both projects.
Everything was working fine until I added some seemingly innocent code, and a reference to System.Web in the DLL.
Now my Sandbox project can't see the namespace of the DLL project. I didn't change anything which I believe should have affected this.
If I delete the project reference to the DLL from the Sandbox references and re-add it, then the red underlines all disappear and the colour coding comes back for all my classes etc; but as as soon as I try to build the solution, the whole thing falls apart again.
When I right-click the DLL project in the Sandbox's references and view in object browser, I can see the namespace and all the stuff in there.
I have a feeling this might be some sort of bug?
Is this some sort of VS2010 bug? I had this same issue a few months ago and I could only fix it at the time by making a whole new project and re-importing my files. This time, however, I have a bajillion files and will only do that as a last resort!
Edit:
After panickedly going through and undoing all my changes, trying to find what caused the problems, it seems to be this line:
string url = "http://maps.google.com?q=" + HttpUtility.UrlEncode(address);
If I comment out this line, then I get no namespace errors and the project builds fine. I can't see anything wrong with this line though.
I'm ready to declare this a bug in VS2010, this has bitten way too many programmers already. The fix is easy: Project + Properties, Application tab, change Target Framework to ".NET Framework 4" instead of the Client Profile that is selected by default.
System.Web is not included in the client profile. Having this option in the first place is quite silly, the client profile is only 15% smaller than the full version of .NET 4.0. Having it selected by default is even sillier. But I digress.
UPDATE: mercifully this all got fixed in VS2012. Which no longer makes the client profile the default for a new project. And the client profile got retired completely in .NET 4.5, good riddance.
Check to make sure that both projects are using the non-client profile for their target framework (go to each project's properties to do this).
One possibility is that the target .NET Framework version of the class library is higher than that of the project.
I faced this problem, and I solved it by closing visual studio, reopening visual studio, cleaning and rebuilding the solution. This worked for me. On some other posts, I have read the replies and most of users solved the problem by following this way.
Try building only the project with the Sandbox dll first independently.
Then point your executable project to the required dll and ensure copy local is set to true. in reference settings.
Tthen build the executable project.
Changing the target framework from the ".NET Framweork 4 Client Profile" to ".NET Framework 4" worked for me with a similar problem. I agree that the client profile doesn't seem to have much of an advantage to using it. I seem to get nailed with weird errors that I hunt for until I remember that Visual Studio defaults to the client profile. I guess the moral of the story when getting an error is: if "Rebuild Solution" doesn't work, check the Target framework...
If you tried already doing the Framework change, and still not worked, I hope this works for you (as it did for me): Simply add the necessary references from within your projects. Very obvious but I was doing it wrong until I found what was the issue.
I just had this issue and it turned out to be I had multiple namespaces being used that had the same object name (i.e. business objects had the same names as mvc models);
Fully qualifying the names fixed the issue for me.

the type or namespace name could not be found (Reference present)

After I build a few of my references, which are present in the project and accessible through intellisense before the build is performed.
Unfortunately none of my projects are set to target Client Profile, as answered in this thread.
The type or namespace name could not be found
This seems to be the most common cause, does anyone know what else other than this can cause the same issue?
Edit:
The Types that aren't found are all from the referenced DLLs. I have the correct using directives for these and they are present in the resource folder, however they become underlined red after a build (I did try cleaning to).
My initial thought was the framework (the project is on v3.5), but I checked all my resources working or otherwise all where on v2 bar a few (working ones) on v4 which I removed temporarily to make sure we're causing issues.
Unable to access the project from my current location but will post any requested specifics as soon as I can.
edit:
Resolved the issue by deleting all of the custom class libraries... found and rebuilt each of their projects then added the new DLLs back into the project. Stored libraries weren't very organised, so I probably have some confliction between old/new versions.
Have you read the warning in the error list? You might need to install nuget package used by the referenced projects
for me the error warning was
All projects referencing "project file" must install nuget package Microsoft.Bcl.Build.
Are the projects being built correctly ?
Sometimes, you need to manually generate them (right click on them, generate), before being able to run a full build.
I dont exactly know why, but this might be the way to go for you.
~A few simple things to try before getting into more complicated water...
Try clicking:
Build->Clean Solution
Build->Build Solution
If this doesn't work, check your using statements are all there and correct, check your references all still exist.
I had a similar issue today, and I thought I would mention it here in case it helps someone else out. In my case, I have a VB.net Class Library which is referenced by a C# class library. The solution would build fine, but in the IDE, as soon as I started editing a file in the C# project, I would get errors about not finding a reference to the VB.Net library. It turns out that the VB.Net class library had a reference to System.web (lowercase w). I'm not sure how that came about -- but the solution was to delete that reference and replace it with a reference to System.Web (uppercase W).
Make sure all the projects in your solution have the same "Target framework" value

Categories