BC30002 Error Unable to reference .net standard 2.0 components from .net framework 4.8 - .net-standard-2.0

I have a .net standard 2.0 C# project which simply has the following content in one of the C# files:
namespace person.contact
{
public class contactDetail
{
public long contactNumber { get; set; }
public decimal contactAmount { get; set; }
}
}
I also have a .net framework 4.8 project in VB.NET that now references this project using a project reference that points to the .CSPROJ location
Within the .net framework 4.8 project, one of my files calls up the above public class like so:
Dim clientContact As New person.contact.contactDetail
clientContact.ContactNumber = 12345
clientContact.contactAmouunt = 1.00
Now my VS 2019 can go to the definition when I F12 on contactDetail in the vb file and runs without a problem. When I do a clean build though I face the error:
error BC30002: Type 'person.contact.contactDetail' is not defined.
Both projects are also signed however I do know that as .net standard is higher there could be an issue with the DLL? I have however had this working before.

May be, because of multiple reference of different version exist in you project. remove all references and add again the single reference.

Related

Unable to generate database tables from Migration MySQL Ef-Core

I am trying to generate database and tables using EF Core Migrations. I have a Class Library Project which has all the necessary entities and migration datas . I am referencing Class Library Project in another ASP.NET Core 2.1 Web Application .
When running
add-migration initial
command in Nuget Package Manager Console choosing Class Library Project, Migration file is generated in Class Library Project which is fine.
When I run command
update-database
choosing both class libary and web project, I get the message stating that :
No migrations were applied. The database is already up to date.
My DbContextClass:
public class UserDbContext:DbContext
{
public UserDbContext(DbContextOptions<UserDbContext> options) : base(options){}
public DbSet<LoginSession> login_sessions { get; set; }
public DbSet<Authentication> authentications { get; set; }
public DbSet<RolePermissionMap> role_permission_maps { get; set; }
public DbSet<Entity.User> users { get; set; }
public DbSet<Role> roles { get; set; }
public DbSet<UserRole> user_roles { get; set; }
}
I tried running
dotnet ef database update
command from console choosing Class Library project, I got an error message saying:
The specified framework version '2.1' could not be parsed The
specified framework 'Microsoft.NETCore.App', version '2.1' was not
found.
When I copied all important files from Class Library to another web application project i.e, migration file and web project in same file, everything works fine.
I am wondering why I got that error and unable to find solution when class library and web application are in separate files. Can anyone help me? I have many class libraries referenced in web application. So, I cannot port all the necessary files to another web application just to generate database tables.
I've run into similar issues before.
Two suggestions:
Please consider nuking your entire "Migration" (all directories, files, etc) from your project, then re-running dotnet ef migrations add..., followed by dotnet ef database update...
Consider using the Pomelo data provider for MySQL:
https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql

MySQL Data Provider Not Showing in Entity Data Model Wizard

I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database
Environment:
MySQL Server 5.7.21
MySQL for Visual Studio 1.27
Connector/NET 6.10.5
Visual Studio 2015
To Reproduce Issue:
Step 1: Add new item 'Ado.net Entity Data Model'
Step 2: Selected 'EF Designer from database' and click 'Next'
Step 3: Clicked 'New Connection'
There is no mysql connector available.
Other Details:
I already added "System. Runtime" deal as it shows error when installing Mysql. data. Ef6 from nugget
I changed "CopyLocal= true" in 'System. Data' assembly reference
I tried the same steps in Visual Studio 2017. Here I can see the provider in the step 3 but after click ok dialogue closed instead of showing table list
In Visual Studio 2015 and 17 initial time it shows the provider. when I tried next time it's not displaying
Please help. I am checking this for 2 days
To start working with VS 2013 and EF 6
Install the MySQL for Visual Studio 1.1.1
Install the Connector/Net 6.8.1 product.
To work with Database first please do the following
Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
Add the provider to your app/web config file on the providers for Entity Framework section with the following line:
Before you run the Wizard compile your application so the new changes are applied.
To work with Model First please do the following
Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
Add the ADO.Net Entity Model new or existing.
Select the T4 template corresponding to MySQL (SSDLToMySQL)
Right click on the model and then select Generate Script to Create Database. (A MySQL script should be generated for you to create your database).
Hope this helps a bit.
MySQL for Visual Studio 1.1.1
MySQL Connector/Net 6.8.1 Beta
As MaDOS mentioned, mySql is not realy supported. If you want to use EF anyway you have to do a code-first-attempt.
You have to write the mapping-classes, and tell EF that it should NOT change the db.
Example context with disabled db-changes
public class MySqlDbContext : DbContext
{
public DbSet<MyOrderClass> Orders { get; set; }
public MySqlDbContext(IDbConnection connection)
: base((DbConnection)connection, false)
{
Database.SetInitializer<MySqlDbContext>(null); // Disable db-changes by dbContext
}
}
You main Problem are the data-types. Outside the MS-world not all data-types are supported (Oracle also got some problems with DateTime). In example-class below the "Created"-column is handled as string, which always works. In your .Net-application, you have to implement "converter"-properties which map to the desired type.
Example-Class with mapping-configuration
[Table("TORDERS")]
public class MyOrderClass
{
[Column("ORDERID")]
public long Id { get; set; }
[Column("CREATED")]
public string CreatedString { get; set; }
[NotMapped]
public DateTime? Created
{
get
{
DateTime tmp;
if (DateTime.TryParse(this.CreatedString, out tmp))
return tmp;
return null;
}
set
{
this.CreatedString = value.HasValue ? value.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
}
}
}
static void Main(params string[] args)
{
MyOrderClass tmp = new MyOrderClass() { CreatedString = "2018-01-01 11:11:11"};
Console.WriteLine(tmp.Created.ToString()); // This is how you want to work
tmp.Created = null;
Console.WriteLine(tmp.CreatedString); // this is surely not what you want to do
tmp.Created = new DateTime(2018,02,02,10,10,10);
Console.WriteLine(tmp.CreatedString); // Check if setter works ;)
}
Im not uptodate which types work, but with this you'll always be able to use EF.
We used it some time ago to access an existing db, which hat an awful db-schema anyway, because of the schema we hat to setup the datatypes anyway ;).
Could it be a 32bit vs 64bit problem?
Example: 64bit driver installed Visual studio is 32bit?
I have that problem all the time with oledb to Informix. your sofware will work perfectly in 64bit, but the tooling is 32bit.

Windows RunTime Component with NetworkCredential in windows 8

I have created sample WindowsRunTimeComponent app in windows 8, with one property my class looks like..
namespace WindowsRunTimeComponentTest
{
public sealed class Class1
{
public NetworkCredential Credentials {get; set;}
}
}
when I tried to build this, its giving error :
Method 'WindowsRunTimeComponentTest.class1.Credentials.get()' returns System.Net.Credentials', which is not a valid Windows Runtime type. Methods exposed to Windows Runtime must return only Windows Runtime types.
I have vs2012.
please any idea what I have to change to resolve this issue?
My best guess is, when you create a Windows Runtime Component, your component can be used by languages that are not managed, like Javascript or C++.
Those languages don't know how to create specific .NET types such as NetworkCredentials.
For more info see the MSDN documentation here and this stackoverflow post.

How to work with Portable Class Library and EF Code-first?

I'm doing an Windows Phone app where I have a WebApi running in Azure.
I'm using the new "Portable Class Library" (http://msdn.microsoft.com/en-us/library/gg597391.aspx) for my "Models" project which is of cause shared between my WebApi project (this is a normale ASp.NET MVC 4 project) and my Windows Phone project.
This works great and the model (POCO) classes are serialized and deserialized just as I want.
Now I want to start storing some of my Models/POCO objects and would like to use EF Code-first for that, but that's kind of a problem as I can't add the EntityFramework assembly to my "Portable Class Library" project, and really I would not like to either as I only need a small part (the attributes) in my Models project.
So, any suggestions to how a approach this the best way?
UPDATE:
Well, it seems like I can actually add the EntityFramework assembly to the project, but that doesn't really help me, as the attributes I need to use lives in System.ComponentModel.DataAnnotations which can't be used on Windows Phone.
Any suggestions still?
Don't use attributes. Use fluent API instead and create separate assembly for persistence (EF) which will reference your model assembly. Persistence assembly will be use used by your WebAPI layer.
I use a modified approach than Mikkel Hempel's, without the need to use pre processing directives.
Create a standard .NET class library, call it Models
Create a partial class representing what you want to be shared
public partial class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
For non-portable code (like DataAnnotations), create another partial class and use Metadata
[MetadataTypeAttribute(typeof(Person.Metadata))]
public partial class Person
{
internal sealed class Metadata
{
private Metadata() { } // Metadata classes shouldn't be instantiated
// Add metadata attributes to perform validation
[Required]
[StringLength(60)]
public string Name;
}
}
Create a Portable Class Library, and add the class from step 2 "As Link"
When I need my domain-project across multiple platforms, I usually:
Create the standard .NET-class library project for the domain code
For each platform I create a platform specific class library
For each platform specific class library I add the files from the standard .NET-class library as links (Add existing files -> As link) and hence they're updated automatically when you edit either the linked file or the original file.
When I add a new file to the .NET-class library, I add it as links to the platform specific class libraries.
Platform specific attributes (i.e. Table and ForeignKey which is a part of the DataAnnotations-assembly) can be opted out using the pre-processor tags. Lets say I have a .NET-class library with a class and a Silverlight-project with the linked file, then I can include the .NET-specific attributes by doing:
#if !SILVERLIGHT
[Table("MyEntityFrameworkTable")]
#endif
public class MyCrossPlatformClass
{
// Blah blah blah
}
and only include the DataAnnotations-assembly in the .NET-class library.
I know it's more work than using the Portable Class Library, but you can't opt out attributes in a PCL like in the example above, since you're only allowed to reference shared assemblies (which again DataAnnotations is not).

Microsoft Azure dll throws an exception in .NET 4.0

I have developed on EXE project(use for startup task) and use following dlls of Microsoft Azure ,
It's work very well in .Net framework 3.5 but in my case i need to use system.runtime.serialization to serialize class as json string as per following way
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
ms.Dispose();
return retVal;
}
For this i need to change framework to 4.0 but at that time i got exception from Azure dlls
like
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
I think all Microsoft's dlls are with backward compatibly so what's going wrong in this matter?
I should find another way to serialize to json string?
OR
I should to change Azure's dlls to latest version?
Thanks in Advance.
If you write a console app in .NET4 and want to use the RoleEnvironment then you’ll get an error:
The type initializer for ‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’ threw an exception.
To get around this, just add a “useLegacyV2RuntimeActivationPolicy” to the startup tag generated in the default app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
This is because Microsoft.WindowsAzure.ServiceRuntime.dll is a mixed mode assembly. The useLegacyV2RuntimeActivationPolicy attribute is required for referencing any mixed mode assembly, not only the Windows Azure ones.
One thing you might want to check is target framework for your .Net project in Visual Studio. By default when you create a project in VS using .Net framework, it uses ".Net Framework 4 Client Profile". Try changing it to ".Net Framework 4" and see if that helps.