Visual studio for Mac looks into different class than referenced - c#

After accidentally hitting rename of my skv_match class to skv_player class I have issue with my ReadMatches method. The Visual studio keeps telling me, there is no definition of methods in class skv_player when I use class skv_match instead (after I renamed the class back to skv_match).
I am desperate and don't know if I am doing something wrong or Visual studio for Mac is. Does anybody know how to solve this or did I miss something in the code?
I tried to restart the app and laptop, rebuild and clean project. I also tried deleting the figuring classes, creating them again and pasting the original content in them.
public string ReadMatches()
{
var matches = _context.skv_match.AsNoTracking();
StringBuilder sb = new StringBuilder();
if (matches == null)
{
return "No matches found";
}
else
{
foreach (var skv_match in matches)
{
sb.Append($"Match id: {skv_match.id }\r\n");
sb.Append($"Match results: {skv_match.home_team}");
sb.Append($"{skv_match.home_score }:");
sb.Append($"{skv_match.visitor_score } ");
sb.Append($" {skv_match.visitor_team }\r\n");
}
}
return sb.ToString();
}
public class skv_match
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)]
public int id { get; set; }
public string home_team { get; set; }
public string visitor_team { get; set; }
public int home_score { get; set; }
public int visitor_score { get; set; }
}
I get error: "'skv_player' does not contain a definition for 'home_team' and no accessible extension method 'home_team' accepting a first argument of type 'skv_player' could be found (are you missing a using directive or an assembly reference?)" and same for other methods
I expect the app to just take this without any errors, yet I get error that class I am not referencing misses methods. Before I accidentally hit rename the class everything worked just fine.

Ok my apologies to everyone who took time trying to help me. There was issue in Entity framework DbContext. I don't know if I was just tiredly stupid, or mentioned missclick changed it.
For anyone trying to solve this issue, try Right click on the declaration and "Go to declaration". It will point you to the part where you define it.
To be specific, I clicked on part skv_match at var matches = _context.skv_match.AsNoTracking();

Related

Class property says "File not Found" ... before even being initialized?

I am having the weirdest problem right now ...
I am working on a program that tries to instantiate types (DbContext derivatives) from another project. Because the DbContexts don't simply accept standard parameters but only interfaces from that other projects I had to take some of the other project's assemblies and reference them so I could create dummy-types that implement the interfaces.
The main one is this:
class ContextConfigurationDummy:IContextConfiguration
{
#region privates
private ILogger GetLoggerDummy() => new LoggerDummy();
private ITenantSchemaResolver GetSchemaResolverDummy() => new SchemaResolverDummy();
private CultureInfo GetUserCulture() => new CultureInfo("en-US");
private DatabaseMetadata GetDbMetadata() => new DatabaseMetadata();
private IEntityValidatorFactory GetValidatorFactory() => new ValidatorFactoryDummy();
#endregion
public DbConnection GetDbConnection() => new SqlConnection(#"[insert connection string]");
public RuminantDummy GetRuminant() => new RuminantDummy();
public Func<CultureInfo> UserCulture { get; set; }
public Func<DbConnection> Connection { get; set; }
public Func<IDatabaseMappingRuminant> Ruminant { get; set; }
public Func<DatabaseMetadata> DatabaseMetadata { get; set; }
public IEntityValidatorFactory ValidatorFactory { get; set; }
public Func<ITenantSchemaResolver> TenantSchemaResolver { get; set; }
public Func<ILogger> Logger { get; set; }
public ContextConfigurationDummy()
{
UserCulture = GetUserCulture;
Connection = GetDbConnection;
Ruminant = GetRuminant;
DatabaseMetadata = GetDbMetadata;
ValidatorFactory = GetValidatorFactory();
TenantSchemaResolver = GetSchemaResolverDummy;
Logger = GetLoggerDummy;
}
}
The original interface is this:
public interface IContextConfiguration
{
Func<CultureInfo> UserCulture { get; set; }
Func<DbConnection> Connection { get; set; }
Func<IDatabaseMappingRuminant> Ruminant { get; set; }
Func<DatabaseMetadata> DatabaseMetadata { get; set; }
IEntityValidatorFactory ValidatorFactory { get; set; }
Func<ITenantSchemaResolver> TenantSchemaResolver { get; set; }
Func<ILogger> Logger { get; set; }
}
Everything was working just fine, I didn't look at that part of the code for a while, did quite a few changes to the rest (including to the project itself to adapt it for continuous integration), when I was done I started testing again and, when calling the constructor of ContextConfigurationDummy, I was faced with this:
Note how the debugger has not even tried to evaluate it yet! A "normal" error would be that the value is null and after it tries to evaluate it there would be some kind of exception. Not here. There isn't even any file being loaded in this class. Same error for all the following fields
I figured I had to have broken something while working on the project structure, so I remade the entire project, took only the code, re-referenced the assemblies, left everything at default ... and had the exact same error again. So, it has to be the code right?
Well, I reverted to an old commit through git, ran the program, everything working as it should. Great. Checked the code - the relevant parts are exactly the same, except for the Namespaces which were slightly adapted. So, not the code either?
I went back to my current commit and after trying different kinds of ways to reference the external assemblies I tried something else once again: Just for lulz I went into my Main, the Start of the program and tried to instantiate the class with exactly the same line I used to originally instantiate it: var dummy = new ContextConfigurationDummy();
It works. Everything as expected, my class just instantiates normally.
But as if this wasn't weird enough, I'll do you one better:
After calling the method in the main I kept the program running. I got back to the spot where I originally called new ContextConfigurationDummy(). Back into the constructor and ... it works there as well. Took the line out the main - doesn't work. Back in - works again.
I'm beyond stumped, please help. (and don't tell me to clean my solution, I've done so a hundred times and literally remade the entire thing) .
I'm effectively comibining answers from my own experiences and some google-fu here but.
.NET Version
Make sure you're using the same .NET version. I've had it where I've created a new project with an old .NET version and it's screwed me completely with the same issue.
Assembly Names
Make sure none of your dlls share the same name with the assembly you're bringing in. If you have two MyAssembly.dlls it could be looking for the wrong one / version. Additionally if you've updated the other project at some point, check that all your references are using the same version of a brought in dll.
Nuget Packages
Have you updated any Nuget packages in your project that are required by the other assembly also? (I've had this many times with my unit tests) if so you'll either need to update the other projects nuget packages to the same verison, or possibly add an App.Config file to tell it to use the newer version.
I've never had the same assembly names issue, but I've had the nuget package issue and the .net version issue quite a few times (It's something you just don't think about)

Cannot add Scaffold > MVC Controller with views, using Entity Framework in Asp.NET Core

When I try to add Controller using build-in generator I get following error message:
Where "Brand" is a model class and "ApplicationDbContext" is my data context class.
I never encoutered error like this before. It does not occur all the time (2 success vs 30-40 attempts without changing single line of code). I was able to create Controller for same class minutes ago, but it's really annoying when you try to add something new and try more than 10 times with no results.
Of course, I could write my own controller and views, but I really like using included tools.
I have already repaired VS using "Modify" option in "Add or remove". I'm using latest Microsoft Visual Studio Community (MVSC2015 V14.0.25425.01 Update3).
EDIT:
Brand.cs:
namespace AppBrander.Models
{
public class Brand
{
public int ID { get; set; }
public string Email { get; set; }
public string BrandName { get; set; }
public string CompanyName { get; set; }
public string Description { get; set; }
}
}
Works in brand new project, fails in old - I guess it's just my VS installation being totally messed up. I should have been guessed, but I just did second repair...

TPH EF6.0: Cannot calculate the value of expression

I have 3 classes inherited from an abstract base class:
abstract class PortTaskStep{
public Guid TaskID { get; set; }
[ForeignKey("TaskID")]
public virtual PortChangeTask PortChangeTask { get; set; }
public virtual String CompleteStep() { return string.Empty;}
}
class PortTaskStep_Add:TaskStep{}
class PortTaskStep_Modify:TaskStep{}
class PortTaskStep_Delete:TaskStep{}
public class HncNetScanContext : DbContext
{
public DbSet<PortTaskStep> PortTaskSteps { get; set; }
}
When I try to get data from table 'PortTaskSteps', the query returns :
cannot calculate the value of the expression
Some more details:
public class PortChangeTask{
public ICollection<PortTaskStep> PortTaskSteps { get; set; }
public Boolean CompleteTask(){
foreach (var portTaskStep in PortTaskSteps)
{
portTaskStep.CompleteStep();
}
}
}
The Domain assembly contains the classes mentioned above are referenced by a web project and a web site. And when I debug the function in the web site, everything goes well.However, when I debug the same function in the web project, the results is null.
The Snapshot
For another scene tested in the Web Project:
As shown in the Snapshot, I try to get "PortTaskSteps". And the result is null. However, after I uncomment the "textQuery", the result is a list of PortTaskStep.
The Snapshot
I think something is going wrong in webconfig or environment of the Web Project, however, I cannot figure out the point...:(
How can I resolve the problem?
Thanks!
Perhaps the right translation might be "Could not evaluate expression". If so, then most likely it's the problem with Visual Studio. Try to delete all your breakpoints from solution and reinsert them. If that doesn't help you, check this link: Visual Studio 2013 'Could not evaluate Expression' Debugger Abnormality.
If the problem for you appears always on both retrieving data and trying to see it in the debug mode then you might want to check your configuration (maybe you've missed mapping or something important for this table).

StackOverflowException in Microsoft.Html.MainHtmlController on Merge, Annotate,

I am extending VisualStudio 2015 Html Editor. I've decorated my IOleCommandTarget implementing command filter with [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)] attribute. This way my commands will not be run in Annotate and Merge TextViews. However I've ran into problem that MainHtmlController starts to loop on itself as soon as I open Annotate or Merge window. This is my stacktrace:
I have no idea what information could be of help here. My contentype definition looks like this. There is 'htmlx' so that html editor handles the file type.
public class DothtmlContentTypeDefinition
{
public const string ContentTypeName = "dothtml";
//public const string JavaScriptContentType = "JavaScript";
//public const string CSharpContentType = "cs";
[Export(typeof(ContentTypeDefinition))]
[Name(ContentTypeName)]
[BaseDefinition("htmlx")]
public ContentTypeDefinition DothtmlContentType { get; set; }
[Export(typeof(FileExtensionToContentTypeDefinition))]
[FileExtension(".dothtml")]
[ContentType(ContentTypeName)]
public FileExtensionToContentTypeDefinition DothtmlFileExtensionDefinition { get; set; }
...
}
In my desperation I've tried this:
if (textView.Roles.Any(r => r == "VSMERGEDEFAULT_LEFT" || r == "VSMERGEDEFAULT_RIGHT" || r == "ANNOTATE")) {
ServiceManager.RemoveService<HtmlMainController>(textView);
return; }
But that is the most ugly solution ever. And it causes null exceptions somewhere in CommandTargetToOleShim which does not look good. These however are non-fatal and dont take whole visualstudio down. Merge and Annotate are atleast usable.
If needed I will provide more info, but I have no idea what may be relevant.

Why am I missing using directive or assembly reference ASP.NET

I have an ASP.NET project. The namespace is MyNameSpace. Among the cs files in this project is TestClass.cs:
namespace MyNameSpace
{
public class TestClass
{
public string name { get; set; }
}
}
There is another class, Products. In the Product.cs class:
namespace MyNameSpace
{
public class Product
{
public string ProductID { get; set; }
public string Name { get; set; }
public TestClass testClass; <==Doesn't work.
}
}
Why doesn't it work? I've cleaned the solution, rebuilt, etc. There's no Intellisense for TestClass. I'm sure this is something stupid I'm doing but what?
Right click the TestClass.cs file in your Solution Explorer. Make sure the Build Action is set to Compile. You should then get Intellisense on that class and your Product class should be able to see TestClass.
First of all, please don't post questions that ask why "it doesn't work." That's not how programmers think. What happens exactly?
Second, there is no period after the namespace name.
Note: It's hard to tell if the periods are really in the code because this Aravol character has been editing the crap out of the question and it appears he removed one of the periods.

Categories