. Net Discussion

C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Wednesday, February 24, 2021

 Getting error when I try to execute GET Method,

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.


SOLUTION : Example

       [HttpGet]

        [Route("Appointment")]

        [SwaggerOperation(Tags = new[] { "Hospital/Scheduling" })]

        public ActionResult<List<Appointment>> GetAppointmentsV1([FromBody] GetAppointmentsRequest request)

        {

            try

            {

                var result = appointmentApi.GetAppointments(request);

                return result.Result;

            }

            catch (Exception Ex)

            {

                throw Ex;

            }

        }


Change  [FromBody]   to [FromQuery]

Thursday, September 26, 2019

How to debug Windows Service as a console application?.

Step 1: Add a public RunAsConsole method to your service class.

        public void RunAsConsole(string[] args)
        {
            OnStart(args);
            Console.WriteLine("Press any key to exit...");
            Console.ReadLine();
            OnStop();
        }

Step 2: Opt out of the ServiceBase when running as a console

Change Program.cs main method so it opts out of full service mode when running in interactive mode (i.e. as a console), while falling back to normal service behaviour when run by the Service Controller:
 static class Program
    {
        static void Main(string[] args)
        {
            MyService service = new MyService();
            if (Environment.UserInteractive)
            {
                service.RunAsConsole(args);
            }
            else
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { service };
                ServiceBase.Run(ServicesToRun);
            }
        }
    }

Wednesday, September 25, 2019

I have a .NET Windows app that is using MSTDC and it is throwing an exception:

System.Transactions.TransactionManagerCommunicationException: Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool ---> System.Runtime.InteropServices.COMException (0x8004D024): The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024) at System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, ITransactionShim& transactionShim)....


Use this for windows Server 2008 r2 and Windows Server 2012 R2

  1. Click Start, click Run, type dcomcnfg and then click OK to open Component Services.
  2. In the console tree, click to expand Component Services, click to expand Computers, click to expand My Computer, click to expand Distributed Transaction Coordinator and then click Local DTC.
  3. Right click Local DTC and click Properties to display the Local DTC Properties dialog box.
  4. Click the Security tab.
  5. Check mark "Network DTC Access" checkbox.
  6. Finally check mark "Allow Inbound" and "Allow Outbound" checkboxes.
  7. Click ApplyOK.
  8. A message will pop up about restarting the service.
  9. Click OK and That's all.
Note: Sometimes the network firewall on the Local Computer or the Server could interrupt your connection so make sure you create rules to "Allow Inbound" and "Allow Outbound" connection for C:\Windows\System32\msdtc.exe


Still Not working  Then Use below Enlist=False in the connection string like below


Data Source=<<SQLSERVERNAME>>;Initial Catalog=<<DBNAME>>;Integrated Security=SSPI;Enlist=False;"

Monday, September 9, 2019

Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' or one of its dependencies. The system cannot find the file specified.?



Solutions:

1. Edit the unit test .csproj and change the item references from <Shadow Include="Test References\namespace.accessor" /> to <None Include="Test References\namespace.accessor" /> (Shadow => None).

2 Better yet, simply delete all the .accessor files from the unit test project's Test References folder.

This really works for me.

Saturday, December 26, 2015

Introduction to SASS

SASS (Syntactically Awesome Stylesheets) is a stylesheet scripting language for CSS. With SASS you get the power to use features like variables, mixins, nesting etc. thereby decreasing the overall complexity and length CSS sheets. It creates reusable functions and thus increasing code maintainability. The initial version of SASS had an intended syntax, but the later version a new syntax was introduced which did not care about indentation levels or white-space. It uses brackets and semi-colons just like CSS. This version of SASS is called SCSS (Sassy CSS).

The official implementation of Sass is open-source and coded in Ruby, however, other implementations exist, including PHP, and a high-performance implementation in C called libSass. There's also a Java implementation called JSass. Additionally, Vaadin has a Java implementation of Sass. Sass supports integration with the Firefox extension Firebug.

So we will start with few features of this scripting language for CSS. We have following features which will be discussing in little details below.

Variables
Just like in other scripting or object oriented languages now in CSS we can have variables to store information that could be reused. You can assign any font, color, or any other CSS attribute to a variable which you may use throughout the code. SASS uses $ symbol to denote a variable.
E.g
$red-color: #ff0000;

.menu-navigation {
   border-color$red-color;
   color:
   darken($red, 10%);
   }

Interesting fact here is that in variable names hyphen and underscores can be used interchangeably. Variable could be made global with !global keyword.

Rules and Directives
You can think of Mixins as functions which can also take parameters if required. A Mixin helps you create a group of CSS declarations which you may want to reuse throughout you code multiple times. To create a mixin we use @mixin directive. We may pass a parameter in the same which can be used in code below. Once you create a mixin you can call it using @include

a.     @import
This rule is used to import scss and sass files at the top of file

b.     Nested @import
To import within CSS rule

c.      Partials
Partials are similar to partial views in MVC. To modularize large CSS files one may create a separate partial class containing small code snippets.
Partials classes are created with a prefix underscore like _Partial.scss. These partials are then used using @import directive.

d.     @media
To add media style without repeating them

e.     @extend
To add style of one class into another class

f.       @debug
To print value in output.

g.     @warn
This is same as @debug with the difference that they could be turned off with –quiet command

h.     @error
This is used to throw error with  stack trace

                                                 
Mixins
You can think of Mixins as functions which can also take parameters if required. A Mixin helps you create a group of CSS declarations which you may want to reuse throughout you code multiple times. To create a mixin we use @mixin directive. We may pass a parameter in the same which can be used in code below. Once you create a mixin you can call it using @include
E.g
@mixin border-radius($radius) {
       -webkit-border-radius$radius;
      -moz-border-radius$radius;
      -ms-border-radius$radius;
          border-radius$radius;
}

   .box { @include border-radius(10px); }

Control Expressions
We can use control statements  which we use in any oops language like If-Else, For, each, while, etc
       
                div {
              @if $Company == avanade {
                     colororange;
              } @else if $type == accenture {
colorblue;
              } @else {
                     colorblack;
              }
}

Output Style
The output style is used to define how do you want your output CSS to be structured. It has three different options
:Nested - It add the indentation to each rule
:Expanded - it add indentation to each property within the rule
:Compact - Each rule appear in single line
:Compressed – It is kind of minified version of CSS with no whitespaces

Function
User defined functions could be created as in other programming languages and it contains collection of statements as below

@function double-pix($n) {
@return $n * 2;
}

#sidebar { width: double-pix(5); }

Example for practical implementation

Below we have tried to show an example how can we use SASS in our page say an application form.
        Let’s say I define a class for validation error in my .scss file with following attributes

.css-validation-arrow {
    border-color: $red-color;
    position: absolute;
    top: 0;
    left: rem-calc(40);
}

Now when  this SCSS file is compiled, it would get compiled to following class in your.css file.
.css-validation-arrow {
  border-color#FF0000;
  positionabsolute;
  top0;
  left2.5em;
}

Now let’s say I have a span in my .cshtml file of .net project which I would like to highlight for a validation error occurring in my input field of my application form.
I will just have to define this class just like my normal css class and it would fire validation error as specified in css.

       <small class="error">
<span class="css-validation-arrow"></span>
You must select the sender account
       </small>

SASS Installation
 We would need to follow following steps for SASS installation using ruby
1. Download Ruby, http://rubyinstaller.org/downloads/ (NB! Not x64 version)
2. Run installation
2.1. Add Ruby executables to your path
2.2. Associate .rb and .rbw files with Ruby installation
3. Run cmd
3.1. Write: gem update --system
3.2. gem install sass -v "3.2.13"
(The source files can be found under C:\[RUBY]\lib\ruby\gems\[VERSIONNUMBER]\gems)

               
We would now need to install compass to watch over our changes. Follow following steps for compass install
1. In cmd, write: gem install compass -v "0.12.2"

To compile and watch our changes we can use following commands in command prompt Compass compile
● Compile: compass compile [path/to/project]
● Watch the project for changes and compile whenever it does: compass watch [path/to/project]

When a compass project is created a file called config.rb is created. The file contains settings for the compass project that will be used during compilation.

SASS Intellisense in Visual Studio 2012
There are various extension available for SASS Intellisense which could be used. Below is example for mindscape

1. Download Visual Studio extension Web Workbench from Mindscape (is used for Syntax highlighting, intellisense etc),
2. Since Compass will be used for compilation, uncheck all checkboxes from the compile
column in the “Mindscape/Web Workbench Settings” menu option in Visual Studio.

                Or we can extend compass watch tool in Visual Studio using following steps:-

1. Go to Tools/External Tools/Add  in visual studio                                         
1.1. Give title: Compass Watch
1.2. Command: C:\[RUBYROOT]\bin\compass.bat
1.3. Arguments: watch $(ProjectDir)
1.4. Initial directory: $(ItemDir)
1.5. Uncheck “close on exit”
1.6. Check “Use output window”
2. Right click on toolbar in Visual Studio and choose “Customize”
2.1. New/Toolbar name: Compass
2.2. Tab Commands
2.2.1. Toolbar: Compass
2.2.2. Add command…
2.2.3. Tools
2.2.4. External command X (X is the index of Compass Watch in External Tools)