Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 863 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Value cannot be null. Parameter name: source

#1
This is probably the biggest waste of time problem I have spent hours on solving for a long time.


var db = new hublisherEntities();
establishment_brands est = new establishment_brands();

est.brand_id = 1;
est.establishment_id = 1;
est.price = collection["price"];
est.size = collection["size"];

db.establishment_brands.Add(est);
db.SaveChanges();

This gives me an error of

> Value cannot be null. Parameter name: source

stacktrace of

> [ArgumentNullException: Value cannot be null. Parameter name: source]
> System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate)
> +4083335 System.Data.Entity.Internal.InternalContext.WrapUpdateException(UpdateException
> updateException) +87
> System.Data.Entity.Internal.InternalContext.SaveChanges() +193
> System.Data.Entity.Internal.LazyInternalContext.SaveChanges() +33
> System.Data.Entity.DbContext.SaveChanges() +20 ... ...

I just want to add an entity to the table. The ORM is EF.
Reply

#2
I had this one a while back, and the answer isn't necessarily what you'd expect. This error message often crops up when your connection string is wrong.

At a guess, you'll need something like this:


<!-- language: lang-xml -->

<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>

What's happening is that it's 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.
Reply

#3
just as an FYI, somebody may find it useful. I was chasing my tail for this error almost 2 days and was always thinking something big and looking for the classes that might be the issue and finally i found it very stupid issue and it was in my mark up (HTML) code in mypage.ascx. the issue was I have a `<asp:EntityDataSource>` and this has got a include property and I have some other tables listed here and mistakenly a table was there that has been delete from the database recently and I never noticed and it returning null with other entities. I just removed the stupid table from the include list and I am good to go. hope this can help somebody.
Reply

#4
It could be as silly as in my case where savechanges was erroring bcoz the db did not have foreign keys and associations were added to EDM tables. I added foreign keys in the db and regenerated EDM for a fix.

The errors I was seeing are as follows:
Case 1 -> when using DBContext for EDM
Message=Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)


Case 2 -> when using ObjectContext for EDM
Message=Unable to update the EntitySet 'Contact' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

(Just wanted to throw it in there in case it helps someone).

Reply

#5
In MVC, View screen is calling method which is in Controller or Repository.cs and assigning return value to any control in CSHTML but that method is actually not implemented in .cs/controller, then CSHTML will throw the NULL parameter exception
Reply

#6
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.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through