Asp.net Mvc 3 - Late Binding Issue With MVC3 ViewBag?
Feb 18, 2011
I'm trying out MVC Scaffolding in a VB.NET MVC3 project and running into an issue with late binding with Option Strict set on (and I want it on).
This works in C#:
public ActionResult Create()
{
ViewBag.PossibleTeams = context.Teams;
[code].....
causes the compiler error Option Strict On disallows late binding. I took a look at the documentation here: [URL] but it wasn't very helpful.
I notice that a new empty application in C# uses the ViewBag in the HomeController but the VB.NET version uses ViewData, so maybe this is a VB.NET limitation.
I started programming in VBA, then graduated to VB6, and I am now using VB.NET 2008 Express.I have read, in the various posts, that I should keep Option Explicit and Option Strict both on, in order that I use correct VB.NET code and not VB6.I am trying to do that but am totally confused with the results of one of my programmes that was running perfectly with Option Strict off, but now advises:Option Strict On disallows late binding. To me it appears that I am using early binding, but to be honest I am not clear on the binding situation. I have checked through a number of google items, and a number of this Forum's items without seeing the light.[code]
i have this code:Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
[Code]...
Error 1: Option Strict On disallows late binding.Im using visual basic 2010 express on a gateway laptop thats running Windows 7 OS How do i resolve this error?
I have a listbox and it it I am showing numbers.It should look like this (line by line) 1,2,3,4,5,6,7,8,9,10,11.....but is is showing it like this 1,10,11,...2,20,21...3,30...ow can I make it that it will show it in number order 1,2,3,4,5......
I'm getting a late binding error message on this specific section of code: objsys.Sessions(shrd.ocSess) Any suggestions as to why I'm getting this late binding error and how to fix it? [Code]
So I am taking a stab at converting a large VBA project I'm working into .NET. It's in VBA right now only because of convenience of a database (MS Access). But having stumbled upon VB 2010 Express, I'm seeing what I can do in .NET to make my project even better.To that end, one trick I am doing in the VBA project involves late binding.[code]To provide a simplified example, lets say I have three classes, clsOne, clsTwo, and clsThree. They are themselves similar, and in .NET, I'm actually reducing the code each has due to proper class inheritance. But I need to understand how to move away from late-binding, which I use in the VBA project.Now reading into VB .NET some, I've come across the 'Of' keyword, and this looks like the holy grail that I've been seeking. Please understand that these example is not actual code, and the issue cannot be solved (as far as I know) by fancy inheritance and overloading/overriding.[code]
I have strongly typed code which throws a Late binding Disallowed due to Strict On exception. Is there a way to allow late binding, without turning my stict option to off?
I have a class from where I need to set objects in another form?
Form1: vb.net Function SetMyObject(ByVal frmTarget As Object) frmTarget.PictureBox1 = Form1.PictureBox1 End Function
(Not tested code, just wrote to show what I mean)So that's the late binding one.I should also say that the frmTarget variable isn't static so thats why I can't make something like Form2.PictureBox1 = Form1.PictureBox1
I like to keep Option Strict On, but in some cases I need late binding.
For example I need to read the value of Geometry.Area when Geometry could be either a Square or a Circle.
It is not my object model, and Square and Circle are not derived nor share an interface that implements the Area property, so I need either a huge Select Case for each geometry type and for each property, or I use late binding.
I tried with this and a few similar variants, but I couldn't get it to work:
Geometry.[GetType]().InvokeMember("Area", Reflection.BindingFlags.GetProperty Or Reflection.BindingFlags.Public Or Reflection.BindingFlags.Instance, Nothing, Geometry, Nothing)
I am trying to get some code to compile after switching Option Strict On. However I am using some Interop with VB6 and passing in a form object ByRef so Form.Caption fails and I can't convert it to type Form because a VB.NET Form doesn't have a caption property.
How can I can get the following to compile with Option Strict ON:
Public Sub EditFormLegacy(ByRef objForm As Object) objForm.Caption = objForm.Caption + " Edited" End Sub
Is there any way to switch option strict off for specific methods?
I have a function where i am opening up an excel doc and spitting some data out to it. I had this working but then needed to make it so that it would work with older versions of excel as well as 2010.
It was suggested on here that i use late binding instead of including the office interop and allow the system select the appropriate version of interop to use.
We are working with an existing native application (most likely written in VB) that loads assemblies and calls methods with "Late Binding." We do NOT have access to its source code. We want to implement this interface in C#, and have the native application call our C# assembly. Is this anything we have to do beyond matching the method names and method signatures to make it work?
I have a hashtable that stores sports players: key = jersey number, value = an array of information...and what I am trying to do is put this information into combobox (but only showing a certain array elements), so for example say this was the information stored in the hashtable:
so what I have done is created an arraylist that will store the items in the combobox.but my problem happends when I try to loop through the array from the hashtable values.
(playerlisting is the hashtable) Dim playerlist As New ArrayList
[code]....
The above works, however since it's a foreach loop I cannot specify which array indexes I want to add onto the "listitem" string.
Dim arr As Array = CType(item.Value, Array) For i = 0 To arr.Length - 1 listitem += arr(i) & " " Next
But, when I try a simple forloop instead I get a "late binding" error with the 3rd line. Even when I cast the arr(i) as a string I get the error. What needs to be changed?
I am new to VB .NET I am having an error:Option strict on disallows late binding, when I execute my script. So I turned off the "option strict off" then I got the error: cannot create activex component, at microsoft.visualbasic.interaction.createobject(string progId,string serverName) what is wrong in this code.
"Cannot create ActiveX component" When I run this simple vbscript I get no errors:
Dim doc set doc = CreateObject("MODI.Document") msgbox "Task completed."
But when I translate it to vb.Net I get the error above:
Dim doc As Object = CreateObject("MODI.Document")
[Code]...
I tried unregistering the DLL (I know it unregistered because the script stopped working) and then I reregistered it again (whence the script started working again), but I still get the error in VB.Net.
I have a VB.NET application which opens Excel and writes data to it. The program works fine in debugging and publishes without problems. The problem I am having is that on some machines the finished program is throwing up the following error: Exception from HRESULT: 0x800A03EC..It happens when the program is trying to communicate with Excel. I am using late binding as this program will role out to our clients and I have no way of knowing what version of Excel they are running.This is the code I am running: (Those variable not in the Dim list are Pubic variables sitting in a seperate module. As I said the code runs fine so I think the problem is the way I am handling Excel)[code]
I have a webbrowser in the form, ele is a HtmlElement on the page in the browser. now, I want to get ele's value (if it exists). if I turn off option strict, then
If (ele.DomElement.value() IsNot Nothing) Then val = ele.DomElement.value.ToString.ToLower() End If
this works. but if I turn on option strict, then it has error for "disallow late binding".
I guess I should use ctype to convert ele.domElement, but what type should I convert it to? htmlelement will not work.
How do I code this routine to work with Option Strict On? I understand it is a late binding problem but I don't know enough about how to correct.
Code: Dim parms As String = "" For Each chk In Me.GroupBox1.Controls If TypeOf chk Is CheckBox Then If chk.Checked Then parms &= chk.Tag.ToString & " " End If End If Next
I am migrating VB 6.0 code to C#.Net via VB.NET. To prevents typr conversion errors, Option Strict needs to be on. However this is giving me the error 'Option Strict On Disallows Late Binding' on these follwowing lines of code. The code is to read the Global Address Book and the contacts before sending mail using MAPI.
I have this declared up top. Public oldDocument As mshtml.IHTMLDocument And this function. Public Function GetFocusedElement() As mshtml.IHTMLElement Dim focusedElement As mshtml.IHTMLElement = Nothing [Code] ..... On the "OldDocument" lines, I get the error "option strict disallows late binding" when I have Option strict on.