One of my colleagues has added a test project to the master branch that includes a Moq reference. Its not even busing used at the time, simply having the reference causes the build and website to fail:
I called it a pseudo random issue in the title because I've also have that happen with the same error but:
System.Buffers
Once it's set, it's pretty consistent, so no clue what the trigger is to throw on a different library.
If I remove the website from the solution, the code builds correctly, but the website still shows the issue in the browser (as you would expect, I guess).
If I remove Moq and all of the traces adding that exist for the dependency (and it's children), the build is working again
Another reason why I call it a pseudo random issue is that I suspect that what I see is a symptom of the issue. Not the issue itself. It just so happens to trigger on System.Runtime.CompilerServices.Unsafe or whatever.
Any ideas / tips on what I can do to:
Find the actual issue
Come up with a solution?
PS: In case it could be important, we are on a deterministic build, not the default.
With more time passed it's clear that its an architectural fault. A thorough restructuring is needed to fix that so sadly no easy answer can be provided for this.
Step 1 : right click to generate
Step 2 : setting
Step 3 : error message
Step 4 : my Model
how to settle this ? i cant generate create form
So far even if you try to add say, another view for an existing controller and an existing action, say ManageController.AddPhoneNumber with the existing view model - AddPhoneNumberViewModel, still the same exception is thrown despite there is already a view for the very same action and controller, using the very same view model.
No need to upload any more screenshots, or anything else, the problem seems to be in the VS 2017 code generator (a scaffolding view issue), and hopefully will be addressed in some of the following updates.
So be patient and use the copy/paste approach, you'll need to redesign your form anyway. Apparently, this is not a solution to your (my) problem, it only says - "you did nothing wrong, it's a VS bug, wait for an update".
I have faced this and similar issues relating to scaffolding a number of times, and my goto solution works pretty much every time - including for this specific issue.
Right click Solution file
Select "Rebuild Solution"
...And then try your action again.
This has worked for me many times in VS2017 and VS2019 - including today with the latest VS 2019.
It seems the scaffolding is being tripped up by something that is already built, for reasons unknown.
I also had the same problem, make sure there are no issues in your controller, I had unfinished code that caused the error, once I commented it out it created the view without any problems.
I got the same issue and I solved it by downgrading the C# version from 7.2 to 7.1 from the project file
which shows an error.
I remembered that I applied some VS code hints which upgraded the C# version. the code hint was to add the paramaters name in the methods calls like
later I tried to add a view and it showed the above problem. after so many hours of searching and reaching to nothing, I started to remember the C# version change
I downgraded the C# version and removed the paramaters names then I added the view successfully.
btw the error has no relation with the model which is a great mislead.
I also had this issue, if you have created or modified the class (being used to scaffold with) and haven't completed a build yet, build the project first and then try again.
.NET is unable to scaffold any classes that haven't been built yet.
I sincerely don't know what happened, reverting to an old version of code fixes it.
Things I tried that didn't work
Rebuild
Clean / delete bin obj folders
use a different model
use a different template
upgrade visual studio
make sure there are no compile errors.
Things I know isn't the problem
Model classes that inherit other classes
Things I suspect is a problem but haven't tested.
generic methods with same parameters only differing by generics constraint
I can provide the code and details if interested.
I had same issue with you, but I manage to solved the problem with following method:
build project (will see build failed).
Solve the project until successfully build the project.
then, add/generate View again. (should be able to auto-generate the View)
Probably is a long time since this issue was posted here, but I got the same problem using the VS2019 (16.9.2) and/or dotnet-aspnet-codegenerator from command line.
After hours and days searching, no of the solutions mentioned above worked for me, and I ended up by find the reason.
The reason behind this was that I was starting first by implementing my Controller which is calling a Web API to get or post data asynchronously. So almost methods were made async.
To solve the problem, I had to scaffold first the controller and keep the default implementation. Then the scaffolding of the views completed successfully.
I have following, simple, problem because I don't have the luxury to actually debug properly right now. This question might even seem dumb to most but I am still unexperienced when it comes to coding.
I am supposed to write a simple console application that connects to a few different clients (and one server) and replaces some files on the C Drive with Adminrights(If I understood it right that's what the C$ is for?). But because something had gone wrong in the past there are actually a few occurences where the filepath differs from the standard, so I have to check with Dictionary.Exists(path) first, to not make it any longer, what is the correct Syntax to properly connect to said folder?
I was thinking about:
Directory.Exists(#"192.168.xxx.xxx\C$\Program Files\...")
I also tried to test it via localhost, but that didn't seem to work because either I am doing it wrong or it is just not intended to work with it?
Well, figured it out now thanks to a tip from Alex K.. Didn't know that this kind of format was called UNC and did some research about it (a bunch of different sites), could easily test it on my own computer like that:
bool test = Directory.Exists(#"\\192.168.10.102\C$\Program Files")
Also works with the domainname "localhost" instead of "192.168.10.102". Both resulted in true.
I have an interesting problem that I am trying to solve. I have the following code below which is basically a function for merging values with an html file and giving me the result set. I am using a hashtable for those purposes.
The function is as follows (Please bear in mind that I inherited this functionality and cannot be changed at present)
public static string ParseTemplate(string _FileName, int _NumberofSomething)
{
Hashtable templateVars = new Hashtable();
templateVars.Add("NameOfFile", _FileName);
templateVars.Add("NumberOfSomething", _NumberofSomething);
TemplateParser.Parser parser =
new TemplateParser.Parser(
System.Web.HttpContext
.Current.Server.MapPath("~/docs/Templatenr.htm"), templateVars);
return parser.Parse();
}
On our dev and live servers it is working perfectly. However I am trying to deploy the app to another production server and get an "object reference not set to an instance of object". It breaks exactly on the "Hashtable templateVars = new Hashtable();" line. So I am a bit puzzled. If it was a coding problem it should not work everywhere surely?
The only differences between the different production servers are the OS and IIS that is running. ie. Server 2005 and IIS7 vs Server2003 and IIS6 (which is the environment that it breaks on). Both have .net framework up to 3.5 installed. Could the older OS and ISS be the problem? Is it a maybe permission/memory thing? though that sounds a bit implausible since all the other .net functionality I am using on the new production server is working perfectly.
All the issues regarding the hashtable that I found, relates to it not being instantiated. However my error happens on the line that is trying to instantiate a Hashtable.
Has anyone had an error like this before and if so how did you solve it? I'd even appreciate suggestions on what to look for and I'll give it a try. I'll post back the outcome too, if anyone else is experiencing this error in future.
I never really got to the bottom of this error. Suggestions for using remote debugging with Reflector Pro did not work either, pointing to some issues with the virtual server the website was running in. Checking log files showed other errors that the .net framework threw out.
The website was moved to a new virtual server using IIS7 and windows server 2008. It worked as is on the new environment.
This is maybe not the ideal solution for everybody and maybe a framework re-install could have solved our problem, but since we were in the process of changing over to a new environment (for other reasons) this solution suited us.
I am dealing with legacy code and in UI I can find some ID's of my objects which are used at run time.
Those id's could help me to find more quickly the portion of code with which I am dealing for that requirement, but I do not know if it is possible to do in debug mode from Visual Studio 2010 (C++ and C#) a search after a value of an object, which was already calculated at run time.
If you have an idea if this can be done or another way to do it (search an object's value in debug mode) or some work around give me a hand, this could save many many, hours of work for each bug with which I will deal.
I'm not exactly sure what your asking but Scott Guru's tips and tricks might help you out.
http://weblogs.asp.net/scottgu/archive/2010/08/18/debugging-tips-with-visual-studio-2010.aspx