Subsonic 3 - SimpleRepository Update = Object reference not set to an instance of an object - subsonic3

Seems fairly straight forward and simple, I am doing the following and getting an 'Object reference not set to an instance of an object.' error. It's a very simple update.
[AcceptVerbs(HttpVerbs.Post)][Authorize(Roles="admin")][ValidateInput(false)]
public ActionResult SaveContent(int id, string content)
{
var page = _repos.Single<Models.Page>(p=>p.PageID == id);
page.PageContent = content;
_repos.Update(page);
return RedirectToAction("Index",new { pagename=page.Name});
}
I can see in the debugger that I am actually getting my object and updating it with new values but the _repos.Update(page); chokes every time.
Anyone else having this issue?

This is a bug of SubSonic 3.0.0.3, you should go to http://github.com/subsonic/SubSonic-3.0/tree/master, get the latest source code and build the dll yourself.

Related

Entity Framework Core metadata is different than model and DB. How to refresh?

I'm new to using EF but it was relatively simple to implement for me, the problem came when I need to change the model. I created a column that I later deleted. However, at runtime the ghost column is causing an Invalid column error.
I have added this method to my context to confirm my suspicion.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
bool destroy = false;
foreach (Microsoft.EntityFrameworkCore.Metadata.Internal.Property p in modelBuilder.Entity<File>().Metadata.GetProperties())
{
if (p.Name == "AppointmentID")
{
destroy = true;
}
}
}
I have tried to use framework core migration tools, adding and removing colums. That works great, but none of this gets rid of the reference to an old column.
Is there a way to reset this? It seems older versions of EF had physical files that were generated as the schemas/definitions of the columns. Is there something like that I could force to be refreshed?

Bing Map throws exception in 'Windows Runtime Component' project

First of all I want to apologize for the English.
I'am develop windows 8.1 store app. On C++/CX language. My solution contains several projects. One of projects has the 'Windows Runtime Component' type, and perform geocoding and reverse geocoding.
For a geocoding I use 'Bing Maps SDK for Windows 8.1 Store apps'(link).
Here's my algorithm:
void addressByLocation(double latitude, double longitude)
{
ResourceLoader^ loader = ref new ResourceLoader();
String^ credentials = loader->GetString("BingMapCredentials");
Location^ location = ref new Location(latitude, longitude);
ReverseGeocodeRequestOptions^ requestOptions = ref new ReverseGeocodeRequestOptions(location);
Map^ map = ref new Map();
map->Credentials = credentials;
SearchManager^ searchManager = map->SearchManager;
task<LocationDataResponse^> reverseGeocodeTask(searchManager->ReverseGeocodeAsync(requestOptions));
reverseGeocodeTask.then([=](LocationDataResponse^ response)
{
if (!response->HasError)
{
//
}
});
}
I've got the problem in this line:
Map^ map = ref new Map();
It always generates an exception with text:
"Platform::DisconnectedException ^ at memory location 0x0396DF80.
HRESULT:0x80010108 The object invoked has disconnected from its clients.
WinRT information: The object invoked has disconnected from its clients."
But I noticed something weird. If add project to the solution which contains UI(xaml), my code in this project works perfectly fine, without any exceptions.
Can somebody specify an error to me? Or give the explanation for this strange behavior.
There is probably other methods to perform geocoding for windows 8.1 store apps, which I don't know yet.
Thanks.

Sitecore: Glass Mapper Code First

It is possible to automatically generate Sitecore templates just coding models? I'm using Sitecore 8.0 and I saw Glass Mapper Code First approach but I cant find more information about that.
Not sure why there isn't much info about it, but you can definitely model/code first!. I do it alot using the attribute configuration approach like so:
[SitecoreType(true, "{generated guid}")]
public class ExampleModel
{
[SitecoreField("{generated guid}", SitecoreFieldType.SingleLineText)]
public virtual string Title { get; set; }
}
Now how this works. The SitecoreType 'true' value for the first parameter indicates it may be used for codefirst. There is a GlassCodeFirstDataprovider which has an Initialize method, executed in Sitecore's Initialize pipeline. This method will collect all configurations marked for codefirst and create it in the sql dataprovider. The sections and fields are stored in memory. It also takes inheritance into account (base templates).
I think you first need to uncomment some code in the GlassMapperScCustom class you get when you install the project via Nuget. The PostLoad method contains the few lines that execute the Initialize method of each CodeFirstDataprovider.
var dbs = global::Sitecore.Configuration.Factory.GetDatabases();
foreach (var db in dbs)
{
var provider = db.GetDataProviders().FirstOrDefault(x => x is GlassDataProvider) as GlassDataProvider;
if (provider != null)
{
using (new SecurityDisabler())
{
provider.Initialise(db);
}
}
}
Furthermore I would advise to use code first on development only. You can create packages or serialize the templates as usual and deploy them to other environment so you dont need the dataprovider (and potential risks) there.
You can. But it's not going to be Glass related.
Code first is exactly what Sitecore.PathFinder is looking to achieve. There's not a lot of info publicly available on this yet however.
Get started here: https://github.com/JakobChristensen/Sitecore.Pathfinder

Sitecore Glass Mapper always null

I am using Sitecore Glass Mapper for a new project I'm setting up.
We are using Sitecore 7.2, latest version of Team Development for Sitecore (TDS) code generation and the latest version of glass.
The code I am trying to execute:
var b = new SitecoreContext();
var c = b.GetCurrentItem<T01_Homepage>();
b is not null. c is null.
var d = b.GetItem<T01_Homepage>("path")
d is null.
I added my assembly in GlassMapperScCustom:
public static IConfigurationLoader[] GlassLoaders(){
var attributes = new AttributeConfigurationLoader(new[] { "Company.Framework.Websites.Corporate", "Company.Framework.Core", "Company.Framework.Common" });
return new IConfigurationLoader[] { attributes };
}
When I look into b.GlassContext.TypeConfigurations all my models are there.
I figured it could be a language issue because the site is in dutch and maybe the wrong language would be resolved incorrectly. This was also not the case.
I disabled WebActivator and added the GlassMapperSc.Start() in my Global.asax Application_Start method.
We are also using Autofac as DI framework. But without it, it still isn't working as you can see above. Also when I create my own custom models without TDS code generation the result of GetCurrentItem<T> is null.
Does anyone have an idea how I can fix this?
Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.
I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.
Most of the times it is a language issue. The mapper returns a null object when you do not have versions in the current or given language.
What can be confusing is that Sitecore.Context.Database.GetItem returns an object, even if it does not have a version in the current language. Be sure to check that item.Versions has any.
Some things you may try (this didn't fit in the comments field)
1) Confirm that the related fields in the Sitecore Item object contain values (so Sitecore.Context.Item for your "c" var and Sitecore.Context.Database.GetItem("path") for your "d" var)
2) Try to encapsulate the GetItem/GetCurrentItem call in a VersionCountDisabler, like this:
T01_Homepage model = null;
using (new VersionCountDisabler())
{
var context = new SitecoreContext();
model = context.GetItem<T01_Homepage>("path");
}
// Do you have data in model now?
3) Try to encapsulate the same call with a SecurityDisabler. Just to confirm it's not a security issue.
4) If you still don't know what it is, please update your question with some (simplified) code for your model.

Adding to a list from another class

I am trying to add the instance of an object that I click on to a list on my control object. However when I do so it says that the reference is not set to an instance of an object. The code I have to instantiate the list on the control object is:
public List<Transform> selected = new List<Transform>();
And I tried to add to it to that list using this code attached to the unit:
if (!selected)
{
// Set selected state
selected = true;
// Add to Selected List
control.GetComponent<ForwardCommandScript>().selected.Add(this.transform);
// Set material colour brighter
oldColour = gameObject.renderer.material.color;
newColour = oldColour + new Color(0.2f, 0.2f, 0.2f);
gameObject.renderer.material.color = newColour;
}
I have tried with transform as well. Later I will try to remove it by finding a reference id that was set when the unit is instantiated so should I try to add the script instead of the object if I need to find its variables and then delete the game object attached to the script. I have tried with the GameObject, transform and the class. I wanted to use the class so I can easily access the variables. I have posted this on unity answers and forums but no one replied in the week it was up and I don't like reposting the same stuff on the same site.
Cheers, Scobbo
Your error NullReferenceException: Object reference not set to an instance of an object states that something in the associated line is null. Since the error message doesn't state which part is null, you have to split your code up and check which part is failing.
I'm not sure how you split it up, but try it this way:
var script = control.GetComponent<ForwardCommandScript>();
if (script == null) Debug.Log("script not found");
if (script.selected == null) Debug.Log("selected is null");
script.selected.Add(this.transform);
Now you should get one of the two messages in your debug log before the exception raises. Either the script was not found and you have to check if it is correctly assigned to the game object and if control is the correct game object, or selected is null which should not happen if you initialized it like you posted...
Thanks for adding the complete Error Message :)
you need to replace
control.GetComponent<ForwardCommandScript>().selected.Add(this.transform);
with
control.GetComponent<ForwardCommandScript>().selected.Add(transform);
because
this
is a reference to the script and not the GameObject. you could also use gameObject.transform which transform is just an abbreviation for