Console App Interface from another DLL Implementation Error - c#-4.0

I have an interface in a DLL and am implementing it in a Console App for Testing
My Interface is as Follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Gemini.Data.Interfaces
{
public interface IUser
{
IEnumerable<IUserDetails> UserProfiles { get; set; }
string AdUserName { get; set; }
}
public interface IUserDetails
{
int UserId { get; set; }
string DisplayUserName { get; set; }
string OfficeCode { get; set; }
string UserEmail { get; set; }
string AdLogin { get; set; }
bool? LastActiveUser { get; set; }
Gemini.Data.App_Consts.Access_Rights UserAccess { get; set; }
bool IsPM { get; set; }
bool IsSPM { get; set; }
bool IsVdbUser { get; set; }
DateTime? LastModified { get; set; }
DateTime? LastLoginUse { get; set; }
int? LastModifiedBy { get; set; }
}
}
and when I try to use it in the Testing App I get the following
The type or namespace name 'IUser' does not exist in the namespace 'Gemini.Data.Interfaces' (are you missing an assembly reference?)
the Console App is as Follows
using System;
using System.Collections.Generic;
using Gemini.Data.Interfaces;
namespace ConsoleApplication2
{
public class User : Gemini.Data.Interfaces.IUser
{
private IEnumerable<IUserDetails> _UserProfiles = null;
#region IUser Members
public IEnumerable<IUserDetails> UserProfiles
{
get { return _UserProfiles; }
set { _UserProfiles = value; }
}
public string AdUserName { get; set; }
#endregion
}
class Program
{
static void Main(string[] args)
{
User u = new User();
Gemini.Data.Main.UserDetails ud = new Gemini.Data.Main.UserDetails(u, "Qpirate");
}
}
}
Visual Studio seems to reference the Interfaces and I can call Go To Definition on the Classes.
Anyone know of something else I can try?
I have already checked that the console app its targeting the same .NET Framework as the DLL.

The same issue happened to me once, and i found out that the assembly name, and console app name were same in my case.
To troubleshoot, i would suggest first make sure that assembly name are different for dll, and console app.
If that does not solve, try specifying different namespaces (both default namespace in project tab, and rename existing namespaces).
If that also does not solve, try to first merger the code of dll into app, and then move one by one. I hope codebase is small in your case.

I eventually just deleted the old Solution and started again, but one thing i did notice was that when i created a console app the Target Framework was ".NET Framework Client Profile"

Related

The property 'Country.IdCountry' is of type 'Guid' which is not supported by the current database provider

I'm trying to use EF Core in combination with Azure CosmosDB. I'm using the following configuration:
Entities:
public class Country
{
public Guid IdCountry { get; set; }
public string Name { get; set; }
public string Code { get; set; }
public string PhoneCode { get; set; }
public IdNameReference Currency { get; set; }
}
public class IdNameReference
{
public Guid Id { get; set; }
public string Name { get; set; }
}
EntityConfiguration class:
public class CountryEntityConfiguration : IEntityTypeConfiguration<Country>
{
public void Configure(EntityTypeBuilder<Country> builder)
{
builder.ToContainer("Country");
builder.HasKey(e => e.IdCountry);
builder.HasPartitionKey(e => e.IdCountry);
builder.HasNoDiscriminator();
builder.Property(e => e.IdCountry).HasConversion<GuidToStringConverter>().ValueGeneratedOnAdd().HasValueGenerator<GuidValueGenerator>();
builder.HasOne(e => e.Currency).WithMany().Metadata.DependentToPrincipal.SetPropertyAccessMode(PropertyAccessMode.Field);
}
}
DbContext OnModelCreating:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ApplyConfiguration(new CurrencyEntityConfiguration());
}
And the IServiceCollection configuration:
services.AddDbContext<MyDbContext>(options => options.UseCosmos(
Environment.GetEnvironmentVariable("Db_ServiceEndpoint"),
Environment.GetEnvironmentVariable("Db_AccountKey"),
Environment.GetEnvironmentVariable("Db_DatabaseName")
)
);
But I'm still getting the following error:
The property 'Country.IdCountry' is of type 'Guid' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'
EDIT: I forgot to specify. This happens when I try to add a new item to the context collection
I'm new in CosmosDB and also in configuration of EF this way.
Do you have an idea, where the problem could be?
Okay, I figured it out, I used wrong the ValueConverter.
I used
.HasConversion<GuidToStringConversion>()
but I had to use
.HasConversion<string>()
or
.HasConversion(g => g.ToString("D"), s => new Guid(s))
I hope it will someone :)

ASP MVC 5 partial, class parameter issue

I am learning and I am trying to change the parameter name of my autogenerated partial class using [Display()] attribute but I am getting this error message.
Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'Student_Age' could not be found (are you missing a using directive or an assembly reference?) EFScuffolding C:\Users\kusha\source\repos\EFModel\EFScuffolding\Models\Students.cs 20 Active
This is my autogenerated code for Student Class
namespace EFDemo.Models
{
using System;
using System.Collections.Generic;
public partial class Student
{
public int StudentID { get; set; }
public string Student_Name { get; set; }
public string Student_Major { get; set; }
public Nullable<int> Student_Age { get; set; }
}
}
This the class I am using to modify the parameters for display
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using EFScuffolding.Models;
namespace EFDemo.Models
{
[MetadataType(typeof(StudentMetaData))]
public partial class Student
{
}
public class StudentMetaData
{
[Required]
public int StudentID { get; set; }
[Required]
[Display(Student_Age = "Student Name")]
public string Student_Name { get; set; }
[Required]`enter code here`
[Display(Student_Major = "Student Major")]
public string Student_Major { get; set; }
[Required]
[Display(Student_Age = "Student Age")]
public Nullable<int> Student_Age { get; set; }
}
}
I am using MVC 5 ,EF6 and Visual Studio 17. Am I missing anything in the code.
Your not using the DisplayAttribute correctly. You need to set its Name property to the text you want to display
[Display(Name = "Student Name")] // not Student_Age = "Student Name"
public string Student_Name { get; set; }
and ditto for the other 2 properties
However, in asp.net-mvc, use view models, not partial classes. Refer What is ViewModel in MVC?

Custom Azure API Apps for Files

I'm looking to create some custom API apps for the sole purpose of creating a/some Logic Apps. With these custom API Apps, I want to pass around files. These files will usually be CSV, ZIP, Excel, TXT, and some other formats - unknown to the consumer until the file is returned (i.e. the client does not dictate the file format).
How does one do something like this in a way that's compatible with Swagger/Swashbuckle, Web API, and Logic Apps? I'll ultimately be tying this into an FTP connector, Dropbox, Onebox, or other file-storage connector.
Does following something like this work or do I need to take a different approach? For example, should I simply work with JSON objects and let my binary be base64-encoded by using a model like this?
public class BinaryFile
{
public string FileName { get; set; }
public string FileExtension { get; set; }
public string DeducedMimeType { get; set; }
public int FileSize { get; set; }
public string FileEncoding { get; set; }
public byte[] FileBinary { get; set; }
}
(this question is cross-posted to MSDN Forums)
The approach I've taken is what I posed in the question with the BinaryFile class. I've broken it out into a few classes. I'm not done - I have some improvements to make still but this is functional right now.
Main class with some common fields:
public class FileResult<T>
{
public string Source { get; set; }
public T File { get; set; }
public IList<string> ErrorMessages { get; set; } = new List<string>();
public bool IsSuccessful { get; set; } = false;
}
This is the <T> in my FileResult<T> class:
public class CsvFile
{
public string Filename { get; set; }
public string Contents { get; set; }
public int Size { get; set; }
}
public class BinaryFile
{
public string FileName { get; set; }
public string FileExtension { get; set; }
public string DeducedMimeType { get; set; }
public int Size { get; set; }
public byte[] Contents { get; set; }
}
Note that in my case, there are some times when I am working with multiple files and not just one, so what could appear to be some common fields are still within the type passed in as the <T> so I can have something like FileResult<IEnumerable<CsvFile>>.
This is all playing nicely with Swagger, Swashbuckle, Web API, Azure API Apps, and Azure Logic Apps. For the cases where I am returning multiple files to my Azure Logic App, I use the fairly hidden splitsOn feature (that also has some designer bugs, so be careful!) to easily iterate over all of the files. It works very nicely.

Entity Type 'AstNode' has no key defined

I'm porting a data model from EF4 to EF6 Code First. I'm getting the following message when the database creation is attempted. I'm at a loss to understand what is causing this. I don't have any Context, AstNode or JSParser entities. It is also not looking in the Models namespace:
var context = QPDataContext.Create();
var session = context.DataSessions.FirstOrDefault(ds => ds.DataSessionId = sessionId);
Throws this exception:
{"One or more validation errors were detected during model generation:
QPWebRater.DAL.Context: : EntityType 'Context' has no key defined. Define the key for this EntityType.
QPWebRater.DAL.AstNode: : EntityType 'AstNode' has no key defined. Define the key for this EntityType.
QPWebRater.DAL.JSParser: : EntityType 'JSParser' has no key defined. Define the key for this EntityType.
(many more similar errors snipped).
"}
Here is my database context (I've simplified it a bit):
QPWebRater.DAL.QPDataContext.cs:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Core;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using Microsoft.Ajax.Utilities;
using QPWebRater.Models;
using QPWebRater.Utilities;
namespace QPWebRater.DAL
{
public class QPDataContext : DbContext
{
public QPDataContext()
: base("DefaultConnection")
{
Database.SetInitializer<QPDataContext>(new CreateDatabaseIfNotExists<QPDataContext>());
}
public static QPDataContext Create()
{
return new QPDataContext();
}
public DbSet<DataSession> DataSession { get; set; }
public DbSet<Document> Documents { get; set; }
public DbSet<Driver> Drivers { get; set; }
public DbSet<Location> Locations { get; set; }
public DbSet<Lookup> Lookups { get; set; }
public DbSet<Quote> Quotes { get; set; }
public DbSet<Vehicle> Vehicles { get; set; }
public DbSet<Violation> Violations { get; set; }
}
}
QPWebRater.Models.DatabaseModels.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace QPWebRater.Models
{
public partial class DataSession
{
public DataSession()
{
this.Vehicles = new HashSet<Vehicle>();
this.Drivers = new HashSet<Driver>();
...
}
public string DataSessionId { get; set; }
public System.DateTime Timestamp { get; set; }
...
}
public partial class Document
{
public int DocumentId { get; set; }
public int QuoteId { get; set; }
public string DocumentType { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public virtual Quote Quote { get; set; }
}
public partial class Driver
{
public Driver()
{
this.Violations = new HashSet<Violation>();
}
public int DriverId { get; set; }
public string DataSessionId { get; set; }
...
}
}
I solved this by examining all of the DbSet definitions. I had pared down the data model while also upgrading it. I had removed the Lookup model class but neglected to also remove the DbSet<Lookup> Lookups { get; set; } property.
This resulted in the class being resolved as Microsoft.Ajax.Utilities.Lookup. At runtime, EntityFramework tried to add a corresponding database table which failed miserably. If you are running into a similar problem then double check the generic types in your DbSet properties.

ServiceStack RazorRockstars Example - Reserved Route?

I have an issue with the RazorRockstars example. I have renamed the main route (/rockstars) on the Rockstars request class to /properties and now it no longer loads. It appears /properties route is reserved. Is this the case? I wish to use this route in my application.
Works:
[Route("/rockstars")]
[Route("/rockstars/{Id}")]
[Route("/rockstars/aged/{Age}")]
public class Rockstars
{
public int? Age { get; set; }
public int Id { get; set; }
}
Works:
[Route("/blahblahblah")]
[Route("/blahblahblah/{Id}")]
[Route("/blahblahblah/aged/{Age}")]
public class Rockstars
{
public int? Age { get; set; }
public int Id { get; set; }
}
Does not work:
[Route("/properties")]
[Route("/properties/{Id}")]
[Route("/properties/aged/{Age}")]
public class Rockstars
{
public int? Age { get; set; }
public int Id { get; set; }
}
Using /properties doesn't work in development because it matches a folder in your root directory (which hi-jacks the request), i.e. in this case VS.NET's Properties/ folder it uses to hold your projects AssemblyInfo.cs file.
It will work after you rename the Properties folder to something else, or once you deploy since deployment builds doesn't include the Properties folder.

Resources