Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a type mismatch error with a type I cannot see anywhere in my solution?

I am getting the following error in an editor template of mine, ApplicantAddressMode:

error CS0019: Operator '!=' cannot be applied to operands of type 'Comair.RI.ViewModels.ApplicantAddressType' and 'Comair.RI.Models.ApplicantTypesOfAddress'"}

The type Comair.RI.ViewModels.ApplicantAddressType is nowhere to be found. A global solution search of all files for just the ApplicantAddressType returns no results. I changed the name of the enum in Comair.RI.Models from ApplicantAddressType to ApplicantTypesOfAddress to try and avoid an unintentional match, and cleaned out both 32 bit and 64 bit Temporary ASP Internet Files, and yet the error still persists on this line of the editor template:

@using Comair.RI.Models
@model Comair.RI.ViewModels.ApplicantAddressModel
@Html.ValidationSummary(true)
<fieldset>
    <legend>@Model.AddressTypeDescription</legend>
    <ul class="form-column">
        @if (Model.AddressType != ApplicantTypesOfAddress.Residential)
        {

Model.AddressType is declared as:

[ScaffoldColumn(false)]
public ApplicantTypesOfAddress AddressType { get; set; }

I am at my wits end about to start throwing flaming, pointed flags around, like IsResidentialStreetNumber and IsPostalSuburb. I don't think the ambulances will arrive long after that and take me away to peace.

The enum declaration is like this:

namespace Comair.RI.Models
{
    public enum ApplicantTypesOfAddress
    {
        Residential,
        Postal
    }
}
like image 407
ProfK Avatar asked Feb 19 '13 14:02

ProfK


People also ask

How do you fix type mismatch error?

The most important thing to do when solving the Type Mismatch error is to, first of all, locate the line with the error and then locate the part of the line that is causing the error. If your code has Error Handling then it may not be obvious which line has the error.

Why am I getting a type mismatch?

Type Mismatch (Error 13) occurs when you try to specify a value to a variable that doesn't match with its data type. In VBA, when you declare a variable you need to define its data type, and when you specify a value that is different from that data type you get the type mismatch error 13.

How do I get rid of type mismatch error in VBA?

Step 1: Write the subprocedure for VBA Type Mismatch. Step 2: Again assign a new variable, let's say “A” as Byte data type. Let's understand the Byte Data type here. Byte can only store the numerical value from 0 to 255.


1 Answers

The tpe that was suspected missing was declared in a file not included in the project. When you tell VS to build view at compile time, which in normally only does just before rendering them, not when it builds the application assembly, it builds all views, and uses any files they refer to whether they are included in the project or not.

Jim Lamb has a good post on how to do this called Turn on Compile-time View Checking for ASP.NET MVC Projects in TFS Build 2010

I don't know about the TFS Build part though. I don't use that, in my case simply adding the following element to my .csproj file did the trick. Note, if the MvcBuildViews element already exists, it's text value must be true.

<PropertyGroup>
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

Caveat Emptor.

like image 183
ProfK Avatar answered Nov 09 '22 23:11

ProfK