I'm working on a C# Web Application project built in framework 3.5 where - for some odd reason I haven't figured out - the - (non-breaking space) is added.
This is the scenario:
I query certain data that is binded in a GridView. One of the values returned from the database is:
04/03/2013 12:00:00 a.m.
Screenshot shows the value is returned correctly:
But, when this value is binded - i.e: GvEmployee.DataBind(); - in the "RowDataBound" event of the GridView called "GvEmployee", the value is shown as:
4/03/2013 12:00:00 a. m. - note the non-breaking space added.
and the System.FormatException exception occurs:
System.FormatException: 'String was not recognized as a valid
DateTime.'
This error is due the non-breaking space and the a.m. additional string. If I remove those characters - while debugging at runtime - , the DateTime conversion can be done.
This the code where the error occurs:
protected void GvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
string id; // This is a reusable variable.
// Check rows only:
if (e.Row.RowIndex >= 0)
{
// Get the value stored in the given cell at the row:
id = e.Row.Cells[3].Text;
// Here, the value of "id" variable is: "4/03/2013 12:00:00 a. m.".
// But, the value returned by the database is: "04/03/2013 12:00:00 a.m.".
// Check if the "id" variable is not empty...
if (!id.Equals(" ") && !string.IsNullOrEmpty(id))
{
// Here fails, due to the value of "id" variable, that is: "4/03/2013 12:00:00 a. m."
// isn't recognized as a valid DateTime value.
e.Row.Cells[3].Text = Convert.ToDateTime(id, CultureInfo.CurrentCulture).ToShortDateString();
}
}
}
As you can see, the non-breaking space on the string value:
This is very strange since this project is already published and only happens on my notebook - I believe there is some missing configuration in the notebook I'm using for work on this project, but, I haven't found any clue about what that could be - I didn't know about non-breaking spaces until this problem happens to me and I found this answer on Stack Overflow...
I've searched about the root of this issue and I tried solving this by adding in the Global.asax the configuration shown in this source and added here for clarity:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
System.Globalization.CultureInfo newCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.AMDesignator = "";
newCulture.DateTimeFormat.LongDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.LongTimePattern = "HH:mm:ss";
newCulture.DateTimeFormat.PMDesignator = "";
newCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
newCulture.DateTimeFormat.TimeSeparator = ":";
newCulture.DateTimeFormat.DateSeparator = "/";
System.Threading.Thread.CurrentThread.CurrentCulture = newCulture;
}
and searched about how to remove those non-breaking spaces globally = by changing some configuration in the web.config and/or the Global.asax of the project, but, nothing so far that worked.
Other alternatives found are about using regex for removing the problematic characters, but, I'm looking for a global setting to apply - due to this situation happens in all the project - not just one page and not only with the given datetime value posted above, and, I have checked the response from the database and it's correct - the problem must be in the ASP.NET C# Web project, but, I don't know exactly where and why this is happening.
I don't know what else it could be, maybe is the language of the operating system?, or the Culture settings of the computer?...
I'm out of ideas, any help is appreciated.
tl;dr: I applied these changes and settings in Visual Studio - not sure which one is the one who applied the solution to this issue, but, I'll leave it as is - since it worked for me:
Discard the changes I made in the Global.asax file that I described in my question.
Uncheck the Save documents as Unicode when data cannot be saved in codepage option found in this path: Tools > Options > Environment > Documents - credits to this answer.
Download the latest version of the problematic aspx/ascx file from the Source Control - (this project is on TFS) - overwriting the local files1.
Applied this line of code on the Site.master of the solution: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - credits to this answer.
1 I forgot mention that this project is on TFS and when I downloaded the project on this notebook, I got this warning:
"This file contains characters in Unicode format which will be lost if
you save this file as an ANSI encoded text file. To keep the Unicode
information, click cancel below and then select one of the Unicode
options from the Encoding drop-down list. Do you want to continue?"
OK / Cancel
Source of the image
I ignored that warning and I think I select OK -> I think this is the root of the problem.
Long version: The project I'm working is on TFS; when I downloaded the project in the notebook - which is a brand new one - I remember I got the warning that says:
This file contains characters in Unicode format which will be lost if you save this file as an ANSI encoded text file. To keep the Unicode information, click Cancel below and then select one of the Unicode options from the Encoding drop down list. Continue?
I selected OK - if I recall correctly - and the project downloading continued without more warnings.
When I compiled all parts of the project and execute it, all was good - until I came to retrieve some data - for check if all was working fine (since this project uses Oracle as database and in my experience with this project and Oracle is that sometimes, unexpected errors presents) and I got the error I described in the question.
After trying all I could possibly could think of, suddenly I remembered this warning I got when I download the project.
Then, I start searching about how check the encoding of the files in the project and I got this answer (1) - this answer (2) looked promising too, but, when I tried and - as I understand - the first linked answer says to make those steps file by file, manually = which is not viable; about the second linked answer, I could not find the location in the .sln or .csproj file.
I keep searching and added visual studio check aspx encoding on Google, one of the answers was this answer and I added the line on the Site.master of the project - since all pages uses this Master Page:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
When I did execute the solution/project, the non-breaking spaces where gone and the DateTime conversion was successful as is shown in this screenshot:
Related
We support a few languages, for which we have different traductions stored in the Properties of our website. Here are some of them:
Resources.es.resx, Resources.fr.resx, Resources.resx (which contains english traductions).
Sometimes (like 3 times in the last year), our website becomes in french for ALL our english users.
We implemented some logging to try and understand what is happening. The last time the bug occured, what we observed is that when trying to get a sample string from our Resources.resx file, the result was from the Resources.fr.resx file. This was the case for all our users.
This is how we obtained that string:
string englishResource = Properties.Resources.ResourceManager.GetString("Add", new CultureInfo("en-ca", useUserOverride: false));
It's as if the Resources.resx was not found and the language defaulted to Resources.fr.resx.
When the website works properly, the returned string is always from Resources.resx, as expected.
Does anyone know why this is happening and how to fix it ?
EDIT:
here is what we get for an english user when the website is displayed in french:
{
SessionCulture: “en”,
UserLanguages: [
“en-US”,
“en;q=0.9”,
“fr;q=0.8",
“es;q=0.7”,
“ca;q=0.6",
“it;q=0.5”
],
LocalizationSystemLanguage: “en”,
CurrentThreadCulture: “en-CA”,
CurrentThreadUICulture: “en-CA”,
EnglishResource: “Ajouter”,
FrenchResource: “Ajouter”,
SpanishResource: “Agregar”
}
the "EnglishResource" string should read "Add" instead of "Ajouter"
I used to work on an Android/Xamarin project for Android 4.4, API Level 19 that contains an activity with the following code:
private void RadioButtonClick(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
switch (rb.Id)
{
case Resource.Id.radioButton1:
...
The last time I looked at the project a couple of month ago, this used to work just fine. Now I want to continue working on the project for Android 8.0, API Level 26, but when I opened it in Visual Studio 2017 I got the compiler error (field)int ResourceId.RadioButton1 A constant value is expected.
Now this is not a problem in itself, as I can always use if (rb.Id == ...) instead of switch/case, but I would like to know why all of a sudden Resource.Id.radioButton1 is not recognized as a constant anymore, even though it is declared as such in Resource.Designer.cs:
public const int radioButton1 = 2131165244;
Has anyone else encountered something similar?
EDIT: Even stranger is that the project builds without complaint, but deployment is not possible due to the said error.
EDIT: It seems that the build process generates another Resource.Designer.cs file which is put into a folder obj\Debug\designtime. Once the file exists, the activities source code refers for the Id declarations to this new file and not to the original Resource.Designer.cs in the Resources folder.
However, all Ids in the new file are static and not const (which of course is the reason for the compiler error that prompted this question in the first place) and moreover they are all set to zero.
Are there any Android/Xamarin experts out there who can explain what is going on here? Might that even be a bug in Visual Studio 2017/Xamarin?
EDIT: Here is a link shedding some light on this topic: https://forums.xamarin.com/discussion/19369/compiling-resource-ids-static-vs-const
What I don't get is this: Why did the above code work at all considering that this problem is known since 2014?
I was following the documentation on this OrchardProject.net link. I opened have activated the CodeGeneration module and opened the command prompt at the root of the project (Orchard.Web) and write "bin/Orchard.exe" for running the commands. Till then everything is fine. Now when I try to run the following command, it gives me the below exception. The command is:
codegen theme mishrajiTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true
Below is the output of the command.
Creating Theme
mishrajiTheme
Error executing command "codegen theme mishrajiTheme"
Specified argument was out of the range of valid values. Parameter
name: startIndex
Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name:
startIndex
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range
of valid values. Parameter name: startIndex] at
System.String.Insert(Int32 startIndex, String value) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.AddToSolution(TextWriter
output, String projectName, String projectGuid, String
containingFolder, String solutionFolderGuid) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateThemeFromTemplates(TextWriter
output, String themeName, String baseTheme, String projectGuid,
Boolean includeInSolution) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.IntegrateTheme(String
themeName, String baseTheme) at
Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateTheme(String
themeName)
What I am doing wrong here or It is a bug in Orchard code generation module.
Please guide. I am using Orchard 1.10 version.
I solved this problem by changing the CodeGenerationCommands Class in line 434 in Orchard 1.10. the line is :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\r\n"), projectReference);
to this :
solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\n"), projectReference);
i don't know why by \r\n can not found the final EndProject and by changing that to \n it works fine
The line of code in question that has failed is this:
solutionText = solutionText.Insert(solutionText
.LastIndexOf("EndProject\r\n"),projectReference)
.Replace("GlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n",
projectConfiguationPlatforms);
If solutionText.LastIndexOf("EndProject\r\n") doesn't find anything it will return -1 - see the MSDN docs here.
It looks like that is then being passed to the string.Insert which is an invalid out of index.
The only thing that I can think is that your git client or however you got your hands on the orchard source has somehow changed the line endings in the file so it can't find the \r\n.
I'm guessing you are from the indian subcontinent, is your OS running a non-english language? I don't think that the .sln file localises fields like EndProject and I don't think Windows varies its newline character representation but something is going wrong here.
Workaround Solution
This is the very last thing that the codegen theme command does, it has created everything else and just failed to add your project into the Orchard.sln. To get moving right now you can just add it to your solution:
In visual studio, open solution explorer window
Right click on your Themes solution folder
Click Add | Existing project
Navigate to the folder and select your new theme
Potential Bug
It seems like there could be a bug here. Would you be willing to post your .sln file to me via email so I can investigate it further?
I started with the solution here http://social.technet.microsoft.com/wiki/contents/articles/20547.biztalk-server-dynamic-schema-resolver-real-scenario.aspx
which matches my scenario perfectly except for the send port, but that isn't necessary. I need the receive port to choose the file and apply a schema to disassemble. From their the orchestration does the mapping, some of it custom, etc.
I've done everything in the tutorial but I keep getting the following error.
"There was a failure executing the receive pipeline... The body part is NULL"
The things I don't get from the tutorial but don't believe they should be an issue are:
I created a new solution and project to make the custompipeline component (reference figure 19) and thus the dll file. Meaning it is on it's own namespace. However, it looks like from the tutorial they created the project within the main biztalk solution (ie the one with the pipeline and the orchestration) and thus the namespace has "TechNetWiki.SchemaResolver." in it. Should I make the custompipeline component have the namespace of my main solution? I'm assuming this shouldn't matter because I should be able to use this component in other solutions as it is meant to be generic to the business rules that are associated with the biztalk application.
The other piece I don't have is Figure 15 under the "THEN Action" they have it equal the destination schema they would like to disassemble to but then they put #Src1 at the end of "http://TechNetWiki.SchemaResolver.Schemas.SRC1_FF#Src1". What is the #Src1 for?
In the sample you've linked to, the probe method of the pipeline component is pushing the first 4 characters from the filename into a typed message that is then passed into the rules engine. Its those 4 characters that match the "SRC1" in the example.
string srcFileName = pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties This link is external to TechNet Wiki. It will open in a new window. ").ToString();
srcFileName = Path.GetFileName(srcFileName);
//Substring the first four digits to take source code to use to call BRE API
string customerCode = srcFileName.Substring(0, 4);
//create an instance of the XML object
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(string.Format(#"<ns0:Root xmlns:ns0='http://TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE This link is external to TechNet Wiki. It will open in a new window. '>
<SrcCode>{0}</SrcCode>
<MessageType></MessageType>
</ns0:Root>", customerCode));
//retreive source code in case in our cache dictionary
if (cachedSources.ContainsKey(customerCode))
{
messageType = cachedSources[customerCode];
}
else
{
TypedXmlDocument typedXmlDocument = new TypedXmlDocument("TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE", xmlDoc);
Microsoft.RuleEngine.Policy policy = new Microsoft.RuleEngine.Policy("SchemaResolverPolicy");
policy.Execute(typedXmlDocument);
So the matching rule is based on the 1st 4 characters of the filename. If one isn't matched, the probe returns a false - i.e. unrecognised.
The final part is that the message type is pushed into the returned message - this is made up of the namespace and the root schema node with a # separator - so your #src1 is the root node.
You need to implement IProbeMessage near to class
I forgot to add IProbeMessage in the code of article. It is updated now.
but it is there in sample source code
Src1 is the the root node name of schema. I mentioned that in article that message type is TargetNamespace#Root
I recommend to download the sample code
I hope this will help you
Sorry if this question is out of context, but I don't know where else to look and StackOverflow tends to provide the best support. I'm having a problem with FlexPaper not loading the locale for HTML rendering option. It appears to be working for Flash version with no problem, but not for the HTML viewer specifically.
Here is the config which loads the control onto a page:
var searchServiceUrl = escape(ashxDir + "containstext.ashx?doc=" + guid + "&page=[page]&searchterm=[searchterm]"),
docUrl = escape("{" + ashxDir + "view.ashx?guid=" + guid + "&numPages=" + numPages +"&format={format}&page=[*,0]," + numPages + "}"),
configObj = {
DOC: docUrl,
...
DocSizeQueryService: ashxDir + "swfsize.ashx?doc=" + guid,
jsDirectory: "/FlexPaper/js/",
JSONDataType: "jsonp",
localeDirectory: "/FlexPaper/locale/",
localeChain: "en_US"
};
This is exactly how I've found it while looking through documentation and everything else, but it simply does not work for me. I've scoured the internet and nobody else seems to have this problem. Unfortunately when I click on the print button all of my labels and buttons show 'null'. Here is a screenshot of what I get when I try to load the page in the HTML viewer:
If you notice in my configuration above, the localeDirectory is set as a sibling directory of the js directory. The locale directory has all of the valid directories under it which hold the localized strings for various languages (ie. en_US, zh_CN, etc..). I've even tried moving the locale directory around the system to see if it is expecting a different "root", but again to no avail...
Any information would be greatly appreciated.
i had that "null" problem in my PHP set up of flex paper in that i put locale & js folder in my location so it is not fetching correct path so i put correct path in default page from where $('#documentViewer').FlexPaperViewer({ defines i just put below paths :
jsDirectory:"http://{xxx}/subdirectory/assets/js/",
localeDirectory:"http://{xxx}/subdirectory/assets/locale/",
may be this will help others
We found the problem and I realize that I never updated the case with the 'Answer'. The fix was directly related to a wrong url which fed the localized strings to the dialog. We were only able to track it down by interrogating the HTTP Request using Chrome Web Tools. It wasn't a complex fix, but it proved to be a complex issue to track down and diagnose properly.
Hope this helps someone someday.