c# – Value cannot be null. Parameter name: source
c# – Value cannot be null. Parameter name: source
Somewhere inside the DbContext is a value that is IEnumerable
and is queried with Any()
(or Where()
or Select()
or any other LINQ-method), but this value is null
.
Find out if you put a query together (somewhere outside your example code) where you are using a LINQ-method, or that you used an IEnumerable
as a parameter which is NULL.
I had this one a while back, and the answer isnt necessarily what youd expect. This error message often crops up when your connection string is wrong.
At a guess, youll need something like this:
<connectionStrings>
<add name=hublisherEntities connectionString=Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True; providerName=System.Data.SqlClient />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type=System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework>
<parameters>
<parameter value=Data Source=localhost;Initial Catalog=hublisher;Integrated Security=True />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Whats happening is that its looking for a data source in the wrong place; Entity Framework specifies it slightly differently. If you post your connection string and EF config then we can check.
c# – Value cannot be null. Parameter name: source
I just got this exact error in .Net Core 2.2 Entity Framework because I didnt have the set;
in my DbContext
like so:
public DbSet<Account> Account { get; }
changed to:
public DbSet<Account> Account { get; set;}
However, it didnt show the exception until I tried to use a linq query with Where()
and Select()
as others had mentioned above.
I was trying to set the DbSet
as read only. Ill keep trying…
Related posts on C++ :
- c++ – Argument list for class template is missing
- c++ – qualified-id in declaration before ( token
- Is it possible to decompile a C++ executable file
- c++ – Pointer to incomplete class type is not allowed
- c++ – How can I create objects while adding them into a vector?
- c++ – error: use of deleted function
- c++ – Reference to non-static member function must be called
- error : expected unqualified-id before return in c++
- c++ – undefined reference to vtable for class constructor
- c++ – Error: expression cannot be used as a function?