Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:18:13+00:00 2026-06-14T23:18:13+00:00

I am attempting to convert a C# implementation of an emailer class using the

  • 0

I am attempting to convert a C# implementation of an emailer class using the RazorEngine to parse a razor template and subsequently send an email into VB.NET. This works great in C#, but I am running into issues with the conversion of a C# dynamic type to a VB.NET ‘object’ type (which from what I can discern is the closest equivalent).

For example, this code works wonderfully in C#:

public static string GetEmailBody(string templatePath, dynamic model)
{
      var template = File.ReadAllText(templatePath);
      var body = Razor.Parse(template, model);
      return body;
}

In my conversion to VB.NET, I ended up with a function call that looks like this:

Private Shared Function RenderEmailBody(strTemplate As String, model As Object) As String

  Dim template As String = File.ReadAllText(strTemplate)
  Dim body As String = Razor.Parse(template, model)

  Return body

End Function

And my call to it looks like this:

RenderEmailBody("mytemplate.vbhtml", New With { .Var1 = "1", .Var2 = "2" })

When I run this, however, the following exception is thrown:

TemplateCompilationException was unhandled by user code
Unable to compile template. 'object' does not contain a definition for 'Var1' and no extension method 'Var1' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

When I inspect model while on a breakpoint, it seems to have Var1 and Var2 assigned correctly, but when I get to the call to Razor.Parse I continually have issues with it not interpreting my dynamic object correctly.

Am I doing something incorrectly here? Or there an inherent incompatibility between the two types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:18:14+00:00Added an answer on June 14, 2026 at 11:18 pm

    Object and dynamic are two completely separate things. In the VB case, what you’ve done is unbox your model completely. They dynamic keyword in C# preserves the actual type without actually knowing it (humanly) at design time. However, when you use Object in this fashion you remove all actual reference to the type. You would need to recast your model to its specific type in order to have access to .Var1 in this case. Your best bet would be to adjust the signature of your method call either to have the specific type you’re looking for or use an interface that your common models can implement that defines the .Var1 or .Var2 properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to convert the following dict into JSON using json.dumps : {
We are attempting to convert a flash frame into a JPEG without using the
I'm attempting to convert a Python application I coded using the cmd module into
I'm attempting to convert a PDF into a single image using GhostScript. Only the
I'm attempting to convert a C header into a Python library using ctypes and
I am attempting to convert some text files into a pdf. Now the easiest
I seem to be running into great difficulty in attempting to convert a Google
Im attempting to Convert a Price (from an API (code below)). public class Price
I am attempting convert this string 2012-02-05T00:00:00+00:00 into a more attractive, nicely formatted string
I'm attempting to convert some effects created in Photoshop into code for use with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.