question

MJ-8053 avatar image
0 Votes"
MJ-8053 asked MJ-8053 answered

Errors caused by Individual User Accounts

I am using Visual Studio 2017.

When I set the project up I selected Individual User Accounts for the Authentication method. I have made no changes to that part of it. I added my models and some controllers and views and now when I try to build my code I get the following errors


 Severity    Code    Description    Project    File    Line    Suppression State
 Error    CS0234    The type or namespace name 'SelectListItem' does not exist in the namespace 'Greenbridge.Models.System.Web.Mvc' (are you missing an assembly reference?)    Greenbridge    X:\DotNet Projects\Greenbridge\Greenbridge\Models\AccountViewModels.cs    21    Active
    
    
 Error    CS0234    The type or namespace name 'SelectListItem' does not exist in the namespace 'Greenbridge.Models.System.Web.Mvc' (are you missing an assembly reference?)    Greenbridge    X:\DotNet Projects\Greenbridge\Greenbridge\Models\ManageViewModels.cs    84    Active
     
 Error    CS0266    Cannot implicitly convert type 'System.Collections.Generic.List<System.Web.Mvc.SelectListItem>' to 'System.Collections.Generic.ICollection<Greenbridge.Models.System.Web.Mvc.SelectListItem>'. An explicit conversion exists (are you missing a cast?)    Greenbridge    X:\DotNet Projects\Greenbridge\Greenbridge\Controllers\AccountController.cs    297    Active

Without starting over from scratch how do I fix this?








dotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MJ-8053 avatar image
0 Votes"
MJ-8053 answered

I tried explaining in the previosu posts that the code was created by Visual Studio. Evidently neither of the respondants have ever created an mvc project using Individual user accounts or they would have known that the code I was referencing was created by VISUAL STUDIO.

Anyway I found the issue as I had found some other code online that was supposed to expand teh indivual user accounts code by creating roles. It was that class

 AuthorizeUserAccessLevel : AuthorizeAttribute

that was causing this one to blow up. I removed that model and all was good with the world again.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx commented

It looks like you created an MVC project. In ASP.NET there is the SelectListItem type that can be used for drop down lists. The problem, I would wager, though is that you are simply missing the using reference. In the editor you should be getting red squiggles under the type name reporting the same error message. Right click the identifier and Quick Actions should pop up. Within here one of the recommended code fixes will be something about adding Using System.Web.Mvc. This will add the using statement and fix the errors.

The only thing I might be concerned about is that your project namespace contains System.Web.Mvc as well. Therefore it is possible you could run into namespace issues but that would depend upon your using statements. Use the Quick Action first and if that doesn't fix the issue then please post the line(s) reporting the error, the using statements you have and the namespace the code is contained in.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is code Generate by Visual Studio. That is why it is perplexing me.

Yes, there are red squiggles.

I made no changes to the code in the Account ViewModels or the ManageViewModels which are created by Visual Studio. And that is where the errors are.

Actually, no the project namespace is Greenbridge Syste.mWeb.Mvc is not part of the namespace it is just how copying the error message formats it on this . If one looks at each class it has namespace Greenbridge.Models on it.

I have attached the code Generated by Visual Studio. As tyou can see if you compare to some you can generate it is the same.


107194-manageviewmodelscs.txt


0 Votes 0 ·

The file you attached doesn't contain the source files the compiler is complaining about. It is complaining about AccountViewModel.cs, ManageViewModel.cs and AccountController.cs.

Note that I'm assuming Nuget is able to download everything properly. Therefore if you closed and reopened the solution and then recompiled do the errors go away?

Did you try quick action on the identifiers and did it present the option of the fix I mentioned?

0 Votes 0 ·
YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @MJ-8053 ,
As far as I think,the System.Web.MVC Assembly is not installed in the GAC. It has to be referenced from

 C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 2\Assemblies

More details,you could refer to below article:
https://stackoverflow.com/questions/2971588/can-i-use-system-web-mvc-from-a-class-library
Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.