Saturday, 28 October 2017

could-not-find-a-part-of-the-path-bin-roslyn-csc-exe

The problem with the default VS2015 templates is that the compiler isn't actually copied to the tfr\bin\roslyn\ directory, but rather the {outdir}\roslyn\ directory
Add this code in your .csproj file:
<Target Name="CopyRoslynFiles" AfterTargets="AfterBuild" Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'">
    <ItemGroup>
      <RoslynFiles Include="$(CscToolPath)\*" />
    </ItemGroup>
    <MakeDir Directories="$(WebProjectOutputDir)\bin\roslyn" />
    <Copy SourceFiles="@(RoslynFiles)" DestinationFolder="$(WebProjectOutputDir)\bin\roslyn" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>
Alternate follow the steps:

Follow steps bellow to delete it
1. Remove Nuget packages, use the following commands from Nuget Package Console
PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
PM> Uninstall-package Microsoft.Net.Compilers
2. After you do this, your web.config file should be auto-updated. In case it is not, look for the below code in web.config file and if it is found, delete this piece of code.
<system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"></compiler>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"></compiler>
    </compilers>
</system.codedom>

Saturday, 18 February 2017

C# - Difference between Throw and Throw ex in C# Asp.Net Basic

Throw

In Throw, the original exception stack trace will be retained. To keep the original stack trace information, the correct syntax is 'throw' without specifying an exception.

Declaration of throw


try
{
// do some operation that can fail
}
catch (Exception ex)
{
// do some local cleanup
throw;
}
Throw ex

In Throw ex, the original stack trace information will get override and you will lose the original exception stack trace. I.e. 'throw ex' resets the stack trace.

Declaration of throw ex


try 
{
// do some operation that can fail
}
catch (Exception ex)
{
// do some local cleanup
throw ex;
}
}

Saturday, 5 September 2015

How to pass HTML5 70-483 Exam ?

It's pretty simple to prepare for 70-483 HTML5 exam,

Recently I became MCSD, passed 3 exam which is coming under MCSD path.

I would like to suggest go with,
1)Microsoft.Actualtests.70-480.v2013-12-31.by.MARY.169q.vce
2) Microsoft.Braindumps.70-480.v2014-04-14.by.TAMARA.31q.vce
(Above both vce downloadable from examcollection.com)


You may find PDF Latest-Microsoft-EnsurePass-70-480-Dumps-PDF-03_53.pdf
any where in the google, please review before go to exam.

Above dumps only give latest question, but real knowledge purpose kindly read book thoroughly. it may give confidence.


Let me know incase if you face difficulty.


Data Reader object to List type model Convert

How we can convert Data Reader object to List type model?
Most of developer are struggling while connecting with the DB, how to iterate those table data!
Developer may be go with DataTable fill using adapter concept, or it may be generic list concept.


I'm giving here pretty simple example for Mapping list.
 public static class Utility
    {
        public static List<T> DataReaderMappingToList<T>(IDataReader dr)
        {
            List<T> list = new List<T>();
            T obj = default(T);
            while (dr.Read())
            {
                obj = Activator.CreateInstance<T>();
                foreach (PropertyInfo prop in obj.GetType().GetProperties())
                {
                    if (!object.Equals(dr[prop.Name], DBNull.Value))
                    {
                        prop.SetValue(obj, dr[prop.Name], null);
                    }
                }
                list.Add(obj);
            }
            return list;
        }
    }

How we can access it?
// We are just passing command and iterating those kind of list.

 using (IDataReader dataReader = cmd.ExecuteReader())
                    {
                        stateDropdownAttribute = Utility.DataReaderMappingToList<StateDropdownAttribute>(dataReader);
                    }  

It's  pretty simple in this way to iterate it.

Thanks,
Gauttam

Friday, 21 August 2015

runAllManagedModulesForAllRequests="true" when getting your MVC routing to work Don't use

It seems to be common advice to make your modules section of your web.config say <modules runAllManagedModulesForAllRequests="true">. In fact this is quite a drastic thing to do to solve the routing problem and has global effects that could CAUSE ERRORS.

You need a module that goes by the name of UrlRoutingModule-4.0 to be running through IIS. Now, since your MVC URLs are likely to end without .aspx these will not be picked up by IIS and run through the intergrated pipeline and therefore you will end up with 404 not found errors. I struggled with this when I was getting started until I found the <modules runAllManagedModulesForAllRequests="true"> workaround.

This highly recommended fix can cause other problems. These problems come in the form of making all your registered HTTP modules run on every request, not just managed requests (e.g. .aspx). This means modules will run on ever .jpg .gif .css .html .pdf etc.

This is:

  1. a waste of resources if this wasn't the intended use of your other modules
  2. a potential for errors from new unexpected behaviour.


Better solution

Fine, so the ranting about <modules runAllManagedModulesForAllRequests="true"> is over. What is a better solution?

In the modules section of your web.config, you can add the UrlRoutingModule-4.0 module in with a blank precondition meaning it will run on all requests. You will probably need to remove it first since it is most likely already registered at machine level. So make your web.config look like this:

?
1
2
3
4
5
<modules>
  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
</modules>

Note: the modules element does NOT contain the runAllManagedModulesForAllRequests="true" attribute because it is evil!