I have a weird visual studio error which is bugging me.
I am using Visual Studio 2010
My solution is small and contains 2 projects:
Project 1 a class library contains the following classes:
Namespace1.DataClass (a serializable class to hold data)
Namespace2.AccessorClass (a class with a method to pull instances of Namespace1.DataClass from a database via Linq to Sql)
Project 2, a console application contains the following classes:
Namespace3.Program (with main function which pulls data from the database and sends it via a wcf service)
Namespace4.WCFProxy (a wcf proxy generated by svcutil)
The WCF client sends objects to the service in the form of:
[System.Runtime.Serialization.KnownTypeAttribute(typeof(Namespace1.DataClass))]
public class SendItem
{
public object Item { get; set; }
public string Label { get; set; }
}
(This is generated by svcutil, so I am paraphrsing to save space)
So, within my proxy class there is a reference to Namespace1.DataClass.
When building my application I first created the project to access the database, I then created my console app, I added a reference from my console app to my my class library and finally I generated my proxy and added it (un-edited) to the console app project.
Everything looks fine, no VS compile errors BEFORE building.
Then, when I build, VS seems to forget the reference from my console app project to my class library project and I get a heap of compile errors accordingly.
If I exclude my proxy class from the project, VS can see the reference again. If I re-add the proxy everything is still fine (no errors and full intellisense support) but click build and everything goes haywire again.
Has anyone come across this issue before?
Cheers
Shane
It was log4net, beware of this behavior in future.
Just to clarify, this problem had nothing to do with WCF as I though it did.
Related
I have created an ASP.NET Core MVC Web application with Individual User Account authentication (Identity).
The template has created one Web project, with a whole bunch of folders, including a "Data" folder which has the migrations for the Identity schema, and ApplicationDbContext.
Now, I have some other projects alongside the web app which will need to consume the data. I don't want them to reference the web project for obvious reasons.
And ideally I don't want my web project to depend directly on EF.
Can I move the data access into a separate class library? And if so, how!?
Create a class library projects.
Move the content from corewebproject/data to class library projects.
Add following from nuget:
Entity Framework
AspNetCore.Identity
AspNetCore.Identity.EntityFramework
Microsoft.entityframeworkcore.SqlServer
Microsoft.entityframeworkcore.Tools
Microsoft.entityframeworkcore.Tools.Dotnet
Build class library projects.
Add as reference to your web project.
Change reference in startup contextdb file location.
If you want to change you sql server from localdb change defaultconnection in appsettings.
Add reference related files.
Build solutions.
Go to nuget package manager console and select your project.
Run next commands:
'Remove-Migration'. it will remove some file including snapmodel file
Add-Migrations "Name"
update database
Check you database: you can see upadated db with aspnetcore individual account related tables.
!!! Enjoy !!!!
Sure, check out the Dev branch on https://github.com/MachUpskillingFY17/JabbR-Core we just moved all data into a separate library including identity. Its still quite a work in progress, but it absolutely works.
I'm looking for recommendations on how to best share code between multiple Visual Studio projects. I'm struggling with a fundamental topic and trying to get some ideas to get over it.
My solution has:
Several web app projects
Several standalone process projects, eg Windows Services and/or console apps and/or Azure WebJobs
An example of functionality which is common to all projects is the need to call some common web service, or the need to read and write from Amazon S3, for example.
Where I struggle is this: Obviously the code that implements the common functionality should be broken out on its own, for example in a separate class library project. To talk to S3 for example, the code needs to know my Amazon credentials, S3 endpoints, etc. - all these things would normally be stored in app configuration files. But I don't like the idea of putting config files in class library projects because it binds a particular implementation to them. But in order to not do that, I have to pass in this information from the calling project. So for example the web app's web.config and the console app's app.config files contain this connection information. When calling the S3 code, I would assumingly pass this config info into the shared code.
However, this seems yucky* to me and I'm not sure why. It still feels to me like I'm "binding" the S3 code (for example) to a particular config method, if that makes sense. I'm not sure if my feeling is a mis-formed bias.
*For example, I may have an arbitrary amount of configuration data that would have to be passed in:
Connection strings
Credentials for web services
API endpoints
Arbitrary data from my app's config settings (which some of the callers will need, but others won't, so lots of times the data will just be useless yet I have to do the work of passing something in)
So every time I added a config variable in my main app, I'd have to modify the constructor of the common code. Things would be in constant motion.
Can you give me suggestions on this?
I like to use Configuration objects as parameters, that way the signature never changes, even if you add/remove properties. For instance....
public class AmazonConfigSettings {
public string AWSkey { get; set; }
public string ApiEndpoint { get; set; }
......
}
Your signature could then always look like:
public MySharedClass(AmazonConfigSettings config) { .... }
Even if (when) Amazon overhauls their webservice settings completely.
Start up VS2013
Create basic WEB API project with defaults
Create basic model (ex. Person class with PersonId and PersonName properties)
Compile
Create Scaffold (pick WEB API with entities)
When I go to create the scaffold using all the defaults I get the error
Add Controller
Scaffolding Failed: WebApplication1.Models.WebApplication1Context is not a System.Data.Entity.DbContext class and does not contain a People property, so it cannot be used as the database context.
ANY IDEAS??
Seems like you are using the Preview build which doesn't support this scenario. Can you please install Preview Refresh and confirm if this fixes your issue?
You can install Preview Refresh from:
http://www.microsoft.com/en-us/download/details.aspx?id=39365
Using Windows Azure and attempting to publish my MVC3 Application. The check box for Execute Code First Migration in the settings panel of the Publish web application is grayed out. What changes do I need to make to be able to enable it?
I believe you see the following "Execute Code First Migration" disabled when you try to publish your MVC application:
This is potentially because either you do not full code written for Code migration in your application as well no or incorrect DB setup in your web.config as described here.
In order to have Code Migration enabled, you must have a DB configured (in case of Windows Azure you need to provide SQL Database info in the web.config) in web.config and a complete class is written on how the code migration will happen depend on your model. Here is an example on how to achieve it.
http://msdn.microsoft.com/en-us/library/dd394698#efcfmigrations
I am assuming that you have Entity Framework model and in your database already (if not then you need to do some reading, answer by #AvkashChauhan would be indeed a good starting point).
However if you do have a model and all the configurations like:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new YourEntityMap());
}
and all the entity mappings like:
public class YourEntityMap : EntityTypeConfiguration<YourEntity>
{
public YourEntityMap()
{
this.HasKey(t => t.Id);
}
}
and you still don't get the darn checkbox enabled you might want to do following steps:
Go to Tools > NuGet Package Manager > Package Manager Console
Then in console write
Enable-Migrations -ContextTypeName Company.Models.YourDevContext
where Company.Models.YourDevContext is your Database Context (look for class that inherits from DbContext should be same one that has OnModelCreating override).
after running command you should get something like:
At this point you should have Migrations folder added to the solution more on how to handle migrations here
Hope this saves you some time.
I am building a controller using scaffolding, from a database model.
The database in the backend is SQL Azure, although I am not sure if that matters.
I entered the connection string, and tested, and it works. I added a new ADO.Net Entity Data Model to my models, and it created the mappings, and I can view the table structure and the FKs when I open the created model, and it looks correct.
I built the solution so the new model is available.
I made sure I have the latest version of Entity Framework, and downloaded the MvcScaffolding from NuGet.
When I add new controller with read/write actions and views, using Entity Framework, I get the following error:
The type 'Website.Models.App.Application' was not mapped.
Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation.
Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.
When I try to add the same controller using MvcScaffolding: Controller with read/write actions and views, using EF data access code, I do not get an error at this step, but when I navigate to the Index View of the new controller I get the same error.
Any ideas about what is causing this error? I have seached long for a solution but everything is coming up empty. Thank you.
Install Net DbContext Generator, if not available from online templates in your Visual Studio 2010
in the entity designer (.edmx file), right click on a blank area, click 'Add Code Generation Item', select 'ADO.NET DbContext Generator' give it a name, click add. >>cant remember why you have to do this :-( but it fixed the same problem for me.
You probably nested your your classes in the main class:
static void Class main(string[] args)
{
public Class YourClass() // This is the wrong location, it's nested in the main class
{
...
}
}
public Class YourClass() // This is the correct location
{
...
}