how to remove helper warnings at visual studio mvc view page

While working on MVC project we can get warnings in the MVC view/ partial view / layout page.

The name ‘ViewBag’ does not exist in the current context

‘System.Web.WebPages.Html.HtmlHelper’ does not contain a definition for ‘ActionLink’ …

‘System.Web.WebPages.Html.HtmlHelper’ does not contain a definition for ‘AntiForgeryToken’ …

These are due to wrong version in the config file. To fix this we need to update the version of the few things and reopen the project.

Here are few things which I have updated:

<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Version" value="3.0.0.0" />
<dependentAssembly>
  <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
 

 

How to fix CLSID {00024500-0000-0000-C000-000000000046} error when using excel component in background code?

We have  a windows Service application which uses Excel Application Object. It used to work on some machines but not all, the error which I am getting is:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

After some struggling I found a solution and it works, solution is:

  • Create directory C:\Windows\SysWOW64\config\systemprofile\Desktop (for 64 bit Windows) or C:\Windows\System32\config\systemprofile\Desktop (for 32 bit Windows) and give full permission
  • Run program “dcomcnfg” Go to “Console Root/Component Services/Computer/My Computer/DCOM Config/” Look up Microsoft Excel and choose properties.
  • Go to Security and Launch and activation permissions->customize->add network, network service, administrator, interactive, system and everyone and give full access
  • Now go to “Identity” and select “The interactive user”.
  • Now go to “Console Root/Component Services/Computer/My Computer”,  right click Properties of “My Computer”, give full access permission to all users.

 

JSON date to Date object – javascript

While working with web services or API with json return, we will get date values in different format, we can’t use this as is where required.

To convert to date object we need to extract integer value and then pass to Date object, below example shows how to get valid date object.

var json = "/Date(-1827639000000)/"
var mytime = new Date(parseInt(json.replace("/Date(", "").replace(")/",""), 10));
alert(mytime);
alert(mytime.toUTCString());

How to Stop Window Error Sound When Typing ‘Enter’ or ‘Esc’

In the KeyDown event, set e.Handled = true and e.SuppressKeyPress = true

OR

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Escape || keyData == Keys.Enter) {
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}

Debugging VS2013/VS2015 Websites Using 64-bit IIS Express

If you are working on ASP.NET MVC web sites in Visual Studio 2013 (VS2013) or 2015 (VS2015), and want to debug 64bit application, you need to do following changes in Visual Studio.

f you don?t do this, you will likely get a message similar to:

?Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format.?

For Visual Studio 2013 and Visual Studio 2015:

Tools
  -> Options
   -> Projects and Solutions
    -> Web Projects
     -> Check "Use the 64 bit version of IIS Express for web sites and projects"`

How to display negative time in excel cell

While working with excel application I found that if we find difference between 2 times is negative then excel doesn’t display time, it shows “##########” instead of values. For positive difference we don’t have any issue.

There are 2 ways to handle this, using 1904 date system and other using custom formula.

To change the date system you need open Advance options of excel and enable the 1904 date system box.

Use the formula:

=IF(D2-A2<0, "-" & TEXT(ABS(D2-A2),"hh:mm"), D2-A2)

 

 

How to fix the outlook issue when its prompting the password again and again

We are using Microsoft Outlook on our desktops or laptops to view emails offline. Some times on start the outlook it prompt us to provide valid password. After providing valid password it prompt again. This will be some irritating.

To fix this type of issue we do have 2 ways:

  • Remove the saved credentials of outlook from windows credentials manager, using these steps:
    • Click Start, click Control Panel, and then click Credential Manager.
    • Note If View by is set to Category, click User Accounts first, and then click Credential Manager.
    • Locate the set of credentials that has Outlook in the name.
    • Click the name to expand the set of credentials, and then click Remove from Vault.
    • Repeat step 3 for any additional sets of credentials that have the word Outlook in the name.
  • In outlook, go to ?Email Accounts -> More Settings? ?> ?Outgoing Server? ?> Check First checkbox and first radio button.

Only Office Error: Server connection lost. The document cannot be edited right now

After hosting of Only Office some time users can get the error “Server connection lost. The document cannot be edited right now“.? To resolve this error we can remove 2 values from the web.config key of the Document Server setup.

By default values:
<add key=”editor.settings.coauthoring.url” value=”/coauthoring” />
<add key=”editor.settings.spellchecker.url” value=”/spellchecker” />

Remove values like that:
<add key=”editor.settings.coauthoring.url” value=”” />
<add key=”editor.settings.spellchecker.url” value=”” />

and reset the IIS.