I have a Entity class (auto-generated) that looks like this:
namespace FicServerData
{
using System;
using System.Collections.Generic;
public partial class Snapshot
{
public Snapshot()
{
this.ComponentQuotes = new HashSet<SnapshotPart>();
}
public int Id { get; set; }
public System.DateTime Time { get; set; }
public string Machine { get; set; }
public string AppName { get; set; }
public virtual ICollection<SnapshotPart> ComponentQuotes { get; set; }
}
}
Then I wrote a utility partial class to looks like this:
namespace FicServerData
{
public partial class Snapshot
{
public IEnumerable<Quote> DerivedQuotes
{
get
{
...
}
}
}
}
So those are both files in the same project and as you can see in the same namespace. Now inside this project I can access the property i added no problem. I can't access it from a project that references it though: i only have access to the Entity class VS has created for me.
What am I missing here?
You cannot access partial classes across projects. The 'parts' of partial classes are compiled to a single class within a single assembly.
The fix for me was to restart the Visual Studio. I am at version Professional 2017.
I had this problem. I found that my consuming project was referencing the source project via an assembly reference rather than a project reference. Further, the assembly being referenced was stored in a drive folder, and that drive folder was added as a reference path in the consuming project. As you would expect, my updates in the source project were compiling, but my referenced assembly was not. I deleted the reference in my consuming project and re-added it as a project reference, et voila! Problem solved!
Don't ask me why my consuming project was using a refence path to access a compiled assembly from another project in the same solution. Please, don't.
Related
I dont know why the "ViewModels" folder reference is missed on my MVC5 login.cshtml file. Please checkout two screen shot to get clear idea about error.
Inside your "ViewModels" folder please check "User.cs" and "UserLogin.cs" class. I think you didn't used its namespace correctly. That's why MVC may not recognising your "ViewModels" folder in reference. The test code bellow you can put on "User.cs" class. I think after you replace "User.cs" codes with mine your "ViewModels" folder should be listed.
User.cs code:
namespace WebApplication4.ViewModels
{
public class User
{
public int UserId { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
You should try:
#using WebApplication4.ViewModels
if you wanna use namespace.
For model you have to pass Class not namespace.
For example
#model WebApplication4.ViewModels.UserLogin
for your UserLogin class. And please check if your class is in right namespace or paste code from UserLogin.cs
I can't create any views without getting this error.
I've tried every fix on Stack Overflow, yet nothing works.
The model:
public class Project
{
public string Name { get; set; }
public int Id { get; set; }
}
The Controller:
public class ProjectsController : Controller
{
// GET: Projects
public ActionResult Project()
{
var project = new Project() {Name = "Things" };
return View();
}
}
When I go into the generated folder "Projects" and create a view I get this error:
Severity Code Description Project File Line Suppression State
Error CS1980 Cannot define a class or member that utilizes 'dynamic'
because the compiler required type
'System.Runtime.CompilerServices.DynamicAttribute' cannot be found.
Are you missing a
reference? WebApplication8 C:\Users\mitch\Documents\Visual Studio
2017\Projects\WebApplication8\WebApplication8\Views\Projet.cshtml 1 Active
It looks like some reference version is invalid or doesn't exist, try adding System.Dynamic.Runtime reference first.
Secondly,Check your .NET target version and make sure there is no dll you are referencing with higher version, and try closing the visual studio and rebuild after reopen.
I have built a Class Library (Portable for iOS, Android and Windows) in VS2015.
I created a public class that having a data type with DataTable.
public class PNAWcfData
{
public int CmdTimeout { get; set; }
public string ErrMsg { get; set; }
public DataTable DTResult { get; set; }
public string XmlResult { get; set; }
}
However, I got error when build the solution.
“The type or namespace name 'DataTable' could not be found (are you
missing a using directive or an assembly reference?)”
I tried to add the using System.Data but still getting the same error. Also tried to add from Project->Reference, but it is telling that component is already automatically referenced by the build system.
Any idea why I am getting this error?
DataTable classes are not available in the PCL. This is a duplicate of Can you use DataSet and DataTables in a Portable Class Library
If you are using Xamarin, you may consider switching to Shared Project instead of PCL.
I am in charge of migrating our companies core libraries from Compact Framework 2.0 that used to run on Visual Studio 2008 to Visual Studio 2015, Update 3 and .Net 4.6. I have created new class libraries and have changed the references to point to the corresponding .Net version of the older libraries. For example, if we had a ProdoctCore library that was referencing Sender.dll and Utils.dll, in the new ProducCoreDotNet library, I have added its references to SenderDotNet.dll and UtilsDotNet.dll. Then I have added the class files of the old Compact Framework to the new solution by adding them "as link". So basically the project names have the extention DotNet but the namespaces have exactly the same name is before.
Now the problem that I'm facing is that I'm getting a strange error:
"The reference type 'IMonitorComponent' is defined in an assembly that is not referenced. You must add a reference to assembly 'Utils, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null'"
However, my UtilsDotNet's version is 1.0.0.0 and the old Utils was version 2.0.0.0.
I've read couple of similar threads at SO but unlike what was mentioned in this question, the IMonitorComponent doesn't have any reference to other assemblies. It's simply an interfaces with couple of properties:
public enum COMPONENT_STATUS
{
ERROR,
WARNING,
OK,
UNKNOWN,
DISABLED
}
public class ComponentStatusProperty
{
public ComponentStatusProperty(string name, COMPONENT_STATUS status, string message)
{
ComponentName = name;
Status = status;
Message = message;
}
public COMPONENT_STATUS Status { get; set; }
public string Message { get; set; }
public string ComponentName { get; set; }
}
public interface IMonitorComponent
{
string Name { get; }
List<ComponentStatusProperty> Statuses { get; }
bool ComponentSoBrokenThatTheDeviceCannotWork { get; }
}
So I'm out of ideas and would appreciate your help. Also, please elaborate on you answers as I haven't done anything like this before.
We finally found the reason. We were using another reference that was using the Utils version 1.5. So I created another class library for that reference and used the new UtilsDotNet as its reference and problem was fixed.
I'm trying to get my typescript definition files generated for my database first entity framework classes using web essentials 2015 with VS 2015.
I followed the example here to generate my .net classes the new way, and i have POCOs for all the tables. e.g.
//module User.cs
public partial class User
{
public int Id { get; set; }
public string User { get; set; }
public DateTime DateOfBirth { get; set; }
}
Usually, i will extend these will some partial classes so i can add some functionality outside of the database, i wouldn't modify my generated code in case i need to regenerate it later.
//module SiteModels.cs
public partial class User
{
public double DaysOld { get { return (DateTime.Now - DateOfBirth).TotalDays ; } }
}
But web essentials only looks at the code in the file that i am generating a typescript intellisense file for, so in my typescript definition i only get:
//generated module SiteModels.cs.d.ts
interface User {
daysOld: number;
}
So the crux of the problem is: when i have 2 partial class in 2 different files, and i am using web essentials to convert one to a typescript definition file, it's not including all of the properties from both partial classes.
Suggestions for alternate routes are acceptable, but they need to work with ASP NET Core.