Object reference not set to an instance of an object. BitShuva - c#

Hi I've downloaded some source code and I'm having some major issues with it straight out of the box. I've not been able to get an answer from the developer and I've not seen anyone else ask this question, but I've looked and looked and looked and I've no idea what's going wrong.
I keep getting this error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:
System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 157: // Expected ID is standard Raven ID: "songs/4321"
Line 158: const string expectedIdPrefix = "songs/";
Line 159: if (song.Id.StartsWith(expectedIdPrefix, StringComparison.OrdinalIgnoreCase))
Line 160: {
Line 161: throw new ArgumentException("ID wasn't in the expected format.");
Visual Studio highlights this bit of code. (denoted by ** **)
using (var session = Get.A<IDocumentStore>().OpenSession())
{
var songFiles = Directory
.EnumerateFiles(Server.MapPath("~/content/sample/music"), "*.mp3")
.Select(f => new
{
Song = new Song(Path.GetFileName(f)),
FilePath = f
})
.ToArray();
songFiles.ForEach(async f => **await f.Song.UploadMp3ToCdn(f.FilePath));**
if (!session.Query<Song>().Any())
{
songFiles.ForEach(s => session.Store(s));
session.SaveChanges();
}
}

Have you tried inspecting songFiles within the debugger? The error seems to suggest that either f.Song or f.FilePath is null/uninitialised.

Found the issue, it's trying to upload music to the CDN specified in the web.config file, and it's looking for the ID of the song. The ID must be generated by Raven database first, and it's trying to pull the ID prior.
Issue Fixed.

Related

c# firestore - Additional information: Path cannot contain empty elements

I'm trying to check if a document exists from my firestore DB but am getting an error before it checks if it exists so I'm a bit confused. I would think my documentsnapshot would return null after the .GetSnapshotAsync() call first however it is just tripping an error and not able to get to the if (docSnapshot.Exists) line.
Context: I am switching over from realtime database to Firestore so the paths are not the same. In this case, lastPath is not empty but it is a realtime database path. Therefore, the line is checking for a realtime database path and is expected to return false.
lastPath = MyCollection/Projects/6f8ebcf7-231f-47e5-ac72-2707cd38ae8f/
The error that occurs: Additional information: Path cannot contain empty elements
So far, I've tried:
The following code is:
DocumentReference documentReference = firestoredb.Document(lastPath); // <<-- throws error not able to continue
and
DocumentSnapshot docSnapshot = await firestoredb.Document(lastPath).GetSnapshotAsync(); // <<-- Also throws error.
Here is the code that follows:
if (docSnapshot.Exists)
{
// do this
}
else if (!docSnapshot.Exists)
{
// do this instead.
}
I can only think of doing a try-catch but I am hoping there is a better way to check if the document exists.
I checked the docs but I keep getting the error and the other posts I've found on SO show mostly for android.
Any and all help is appreciated.

Entity Framework exception suddenly

I have this code in my backend:
using (var context = new Db_EnforcementEntities())
{
try
{
DbContextHelper.SetContextConfig(context, false);
VW_ENF_TviotOnePercentage[] test = context.VW_ENF_TviotOnePercentage.ToArray();
}
}
where VW_ENF_TviotOnePercentage is a view which already exists in my EDMX file.
The above code worked perfectly up until several days ago, and I could fetch records which are identical to the records I could see in the database.
For some reason, when I get to the code now, I get an exception:
Object reference not set to an instance of an object
The stack trace points to:
at System.Object.GetType()
at System.Data.EntityKey.ValidateTypeOfKeyValue
What could go wrong in the database to cause this error?

Application crashes on element reader (pdftron)

I have an issue with pdftron, where opening a certain file, will cause our application to crash with following error:
An unhandled exception of type 'pdftron.Common.PDFNetException' occurred in PDFNet.dll
Additional information: Exception:
Message: Missing resource
Conditional expression: res
Filename : ContentResources.hpp
Function : trn::PDF::ContentResources::GetResource
Linenumber : 26
In our code: it's in the following line that the error occurs:
while ((element = elReader.Next()) != null)
When doing try/catch, we see that the only thing missing from the page is the text that's written diagonally on that page. Does this have anything to do with a missing font maybe ? Don't mind the cursor in the picture, it doesn't know where to go with the text missing.
I can send the pdf file on request.
PDF File
If you are not on the latest version of PDFNet, 6.7.1, then I would first try against that, as the issue might have been resolved already.
Otherwise, since the issue is document specific, you would need to provide that, by either sharing here, or sending to pdftron support.

JSON An error occurred during the compilation of the requested file, or one of its dependencies. ; expected

I'm trying to format this JSON to be able to assign it to DataProviderJSON properly.
It keeps giving me an error on variable 'testing':
An error occurred during the compilation of the requested file, or one of its dependencies. ; expected
using (ContentBySearchWebPart box = GetControlByIDPath(ControlID, this.Page.Controls[0]) as ContentBySearchWebPart)
{
string testing;
testing = "{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":"",\"IgnoreQueryPropertiesTemplateUrl\":false,\"SourceID\":\"8413cd39-2156-4e00-b54d-11efd9abdb89\",\"SourceName\":\"Local SharePoint Results\",\"SourceLevel\":\"Ssa\",\"CollapseSpecification\":"",\"QueryTemplate\":\"#test (ContentTypeId:0x01FD4FB0210AB50249908EAA47E6BD3CFE8B* OR ContentTypeId:0x01FD59A0DF25F1E14AB882D2C87D4874CF84* OR ContentTypeId:0x012002* OR ContentTypeId:0x0107* OR WebTemplate=COMMUNITY)\",\"FallbackSort\":[],\"FallbackSortJson\":[],\"RankRules\":[],\"RankRulesJson\":\"[]\",\"AsynchronousResultRetrieval\":false,\"SendContentBeforeQuery\":true,\"BatchClientQuery\":true,\"FallbackLanguage\":-1,\"FallbackRankingModelID\":\"\",\"EnableStemming\":true,\"EnablePhonetic\":false,\"EnableNicknames\":false,\"EnableInterleaving\":false,\"EnableQueryRules\":true,\"EnableOrderingHitHighlightedProperty\":false,\"HitHighlightedMultivaluePropertyLimit\":-1,\"IgnoreContextualScope\":true,\"ScopeResultsToCurrentSite\":false,\"TrimDuplicates\":false,\"Properties\":{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"PropertiesJson\":\"{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4}\",\"ClientType\":\"ContentSearchRegular\",\"UpdateAjaxNavigate\":true,\"SummaryLength\":180,\"DesiredSnippetLength\":90,\"PersonalizedQuery\":false,\"FallbackRefinementFilters\":null,\"IgnoreStaleServerQuery\":false,\"RenderTemplateId\":\"DefaultDataProvider\",\"AlternateErrorMessage\":null,\"Title\":""}";
box.DataProviderJSON = testing; }
UPDATE: Now it seems to be working but i'm getting a new error on
box.DataProviderJSON = testing;
Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentException: Invalid object passed in, ':' or '}' expected.
This is the JSON:
"{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":\"\",\"IgnoreQueryPropertiesTemplateUrl\":false,\"SourceID\":\"8413cd39-2156-4e00-b54d-11efd9abdb89\",\"SourceName\":\"Local SharePoint Results\",\"SourceLevel\":\"Ssa\",\"CollapseSpecification\":\"\",\"QueryTemplate\":\"#test(ContentTypeId:0x01FD4FB0210AB50249908EAA47E6BD3CFE8B* OR ContentTypeId:0x01FD59A0DF25F1E14AB882D2C87D4874CF84* OR ContentTypeId:0x012002* OR ContentTypeId:0x0107* OR WebTemplate=COMMUNITY) \",\"FallbackSort\":[],\"FallbackSortJson\":[],\"RankRules\":[],\"RankRulesJson\":\"[]\",\"AsynchronousResultRetrieval\":false,\"SendContentBeforeQuery\":true,\"BatchClientQuery\":true,\"FallbackLanguage\":-1,\"FallbackRankingModelID\":\"\",\"EnableStemming\":true,\"EnablePhonetic\":false,\"EnableNicknames\":false,\"EnableInterleaving\":false,\"EnableQueryRules\":true,\"EnableOrderingHitHighlightedProperty\":false,\"HitHighlightedMultivaluePropertyLimit\":-1,\"IgnoreContextualScope\":true,\"ScopeResultsToCurrentSite\":false,\"TrimDuplicates\":false,\"Properties\":{\"TryCache\":true,\"Scope\":\"Site.URL\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"PropertiesJson\":{\"TryCache\":true,\"Scope\":\"{Site.URL}\",\"UpdateLinksForCatalogItems\":true,\"EnableStacking\":true,\"ListId\":\"8837b1d4-c29a-4ab0-9385-f483c19b25ec\",\"ListItemId\":4},\"ClientType\":\"ContentSearchRegular\",\"UpdateAjaxNavigate\":true,\"SummaryLength\":180,\"DesiredSnippetLength\":90,\"PersonalizedQuery\":false,\"FallbackRefinementFilters\":null,\"IgnoreStaleServerQuery\":false,\"RenderTemplateId\":\"DefaultDataProvider\",\"AlternateErrorMessage\":null,\"Title\":\"\"}";
You did not escape the " after QueryPropertiesTemplateUrl. Thus the string is ended there and the compiler is missing the ; to end the statement.
testing = "{\"QueryGroupName\":\"Default\",\"QueryPropertiesTemplateUrl\":" //; The string ends, but is not followed by an semicolon - thus the compile error.
You rather want to use
testing = "[...]\"QueryPropertiesTemplateUrl\":\"\",\"IgnoreQueryPropertiesTemplateUrl[...]";

NullPointerException with MR2 in windows

I have installed Hadoop 2.3.0 in windows and able to execute MR jobs successfully. But while trying with streaming sample in C# [with HadoopSDK's .Net assemblies] the app ends with the following exception
14/05/16 18:21:06 INFO mapreduce.Job: Task Id : attempt_1400239892040_0003_r_000000_0, Status : FAILED
Error: java.lang.NullPointerException
at org.apache.hadoop.mapred.Task.getFsStatistics(Task.java:347)
at org.apache.hadoop.mapred.ReduceTask$OldTrackingRecordWriter.<init>(ReduceTask.java:478)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:414)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:392)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)
Update:
I was able to drill down the problem and found that the exception raised in the following line
matchedStats = getFsStatistics(FileOutputFormat.getOutputPath(job), job);
at org.apache.hadoop.mapred.ReduceTask$OldTrackingRecordWriter.<init>(ReduceTask.java:478)
In the above, the result of 'FileOutputFormat.getOutputPath(job)' returns null, which throws the null pointer exception. Below are the codes for the getOutputPath() function.
public static final String OUTDIR = "mapreduce.output.fileoutputformat.outputdir";
public static Path getOutputPath(JobConf conf) {
String name = conf.get(org.apache.hadoop.mapreduce.lib.output.
FileOutputFormat.OUTDIR);
return name == null ? null: new Path(name);
}
So Is it needed to set value for property "mapreduce.output.fileoutputformat.outputdir" anywhere in the configuration files to get this issue resolved?
Thanks
The problem is that the hadoop services have been started from a different user [SYSTEM in my case] and the mapreduce sample was submitted from my local user. So this makes the issue by returning the FileSystem statistics [for the local user] as Null.
Once i started Hadoop from my local user, the above issue gets resolved.

Categories