Blog from Saravanan Arumugam

Let us talk about Technologies

Category Archives: Exceptions and Solutions

Folders created in solution not being deployed


I had some custom folders I created in my MVC3 application, such as Attachments, Forms etc. which I would use from code. For example, one of my web page would receive file attachments (Files being uploaded from the client side) from the user and store it in Attachments folder in the solution.

When I deployed my application, the these folders I didn’t show up on the Web Server.

Solution

Then I realized that the visual studio while deployment would not deploy any empty folder. Rather, it deploys files; if the file requires a new folder to be created it would create the folder.

So I created a simple text file in each of these custom folders, say AboutTheFolder.txt. This file ensured that the file gets created after creating the folders I was looking for.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated


When I tried to send an email from .Net code, I got the following exception.

Exception

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

Solution

This was because the mail was sent from the office network. By default the credentials in the SmtpClient object is null. The issue was resolved by setting SmtpClient.UseDefaultCredentials to true.

mailClient.UseDefaultCredentials = true;

Error: Schema with target namespace could not be found.


I was debugging a WSDL by downloading it and its reference XSDs in to my local machine. I got the following exception when I used SVCUtil

Exception

Error: Schema with target namespace ‘http://xmlns.oracle.com/Common/schemas/GetEmployeesPayrateRequest.V1′ could not be found.

Solution

We get this exception because the svcutil for some reason is not finding the referenced schema in the local disk. To solve it, try copying the xsd contents and place them as inline schema under <wsdl:types /> tag.

  <wsdl:types>
    <!--<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:import namespace="http://xmlns.oracle.com/Common/schemas/GetEmployeesPayrateRequest.V1" 
                  schemaLocation="GetEmployeePayrateRequest.v1.xsd"/>
      <xsd:import namespace="http://xmlns.oracle.com/Common/schemas/GetEmployeesPayrateResponse.V1" 
                  schemaLocation="GetEmployeePayratesResponse.v1.xsd"/>
    </xsd:schema>-->
    <xsd:schema elementFormDefault="unqualified" targetNamespace="http://xmlns.oracle.com/Common/schemas/GetEmployeesPayrateRequest.V1"
            xmlns="http://xmlns.oracle.com/Common/schemas/GetEmployeesPayrateRequest.V1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="GetEmployeesPayrateRequest">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="EMPLID" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
 
    <xsd:schema elementFormDefault="qualified"
            targetNamespace="http://xmlns.oracle.com/Common/schemas/W_GENERIC_RESPONSE8.v1"
            xmlns="http://xmlns.oracle.com/Common/schemas/W_GENERIC_RESPONSE8.v1"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="GetEmployeePayratesResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="JobRow">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="EmployeeId" type="xsd:string"/>
                  <xsd:element name="EmployeeName" type="xsd:string"/>
                  <xsd:element minOccurs="0" name="EffectiveDate" type="xsd:date"/>
                  <xsd:element name="HourlyRt" type="xsd:string"/>
                  <xsd:element name="DepartmentId" type="xsd:string"/>
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>

Note that usually the WSDL will generate the <xsd:schema/> tag inside <wsdl:types /> element, and will fill it with multiple imports for every reference types. This has to be replaced by the actual schema definitions. I have just commented it out to show where the replacement has to happen.

The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced


I am working on an MVC 3 application where I use an Entity Object as the model to the View. I was getting the following error in the browser.

Exception

Compiler Error Message: CS0012: The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

Solution:

It was interesting that the MVC project by default has the reference to System.Data.Entity namespace. But still the issue was presented. I finally figured out the clue from another word press blog. I had to add the assembly entry in the Web.config to resolve the issue.

  <assemblies>

    <add assembly=System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 />

    <add assembly=System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 />

    <add assembly=System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 />

    <add assembly=System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 />

    <add assembly=System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 />

    <add assembly=System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089/>

  </assemblies>

Note that the complete assembly name is presented in the exception message itself.

Error message 401.2.: Unauthorized: Logon failed due to server configuration.


I was trying to get my MVC 3 web application work through IIS 7.5 Express, and when I ran the application I got the following error.

Exception

Access is denied.

Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.
Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server’s administrator for additional assistance.

 

Solution

As the first step I had to look at the web.config. The authentication mode was set to Windows Authentication.

    <authentication mode="Windows" />
    <authorization>
      <deny users="?" />
    </authorization>

Even though the web.config says that I need windows authentication, IIS Express need to be informed about it.

To resolve it, I did the following.

1. Clicked on the Web Project, and hit F4. (Right click and properties will get you to a different place)

2. Made sure that I can see the Properties Pane. (Not the property window).

3. Select Enabled for the Windows Authentication Property.

image

This would enable the windows authentication and get rid of the exception.