asp.net mvc - Knockout MVC - VB.NET issue with IsAssignableFrom and MethodCallExpression -
i having problems library called knockout mvc. .net wrapper around knockout.js. while works pretty when using in c# based asp.net mvc project, doesn't in vb.net based project , found out why.
protected virtual string visitmethodcall(methodcallexpression m) { ... if (typeof(expression).isassignablefrom(m.method.returntype)) return visitmemberaccess(m.object, m.method.name); throw new notsupportedexception(); }
the condition evaluates false when project calls library written in vb.net. same thing in c#: working perfectly.
since not quite sure causing different behaviour, thought might idea ask community. maybe knows how line translated works both c# , vb.net.
the code can found @ ~ line 260 here.
[edit]
to clarify things: code above not need translated vb.net. problem rather, condition contains returns different results based on whether called c# or vb.net code. believe isassignablefrom behaves differently vb.net , c#... need know how condition work independent of language called from.
[edit] - example following steps reproduce problem:
- create new asp.net mvc 4 project in visual studio 2012 using vb.net
- add knockout mvc via package manager console (install-package kmvc)
ignore error (methods null), nuget script error, , add following line global.asax.vb (application_start) manually:
modelbinders.binders.defaultbinder = new perpetuumsoft.knockout.knockoutmodelbinder()
add following configuration bundleconfig.vb
bundles.add(new scriptbundle("~/bundles/knockout").include( "~/scripts/knockout-{version}.js", "~/scripts/knockout.mapping-latest.js", "~/scripts/perpetuum.knockout.js"))
render scriptbundle in _layout.vbhtml beneath modernizer
@scripts.render("~/bundles/knockout")
add new model models folder
imports delegatedecompiler
public class helloworldmodel
public property firstname string public property lastname string <computed> public readonly property fullname string return firstname + " " + lastname end end property
end class
add new controller controllers folder
public class helloworldcontroller inherits perpetuumsoft.knockout.knockoutcontroller
' ' get: /helloworld function index() actionresult return view(new helloworldmodel { .firstname = "john", .lastname = "doe"}) end function
end class
compile project mvc extension gets know model
- right click index action in controller , select "add view.."
- leave view name , choose create strongly-typed view, selecting helloworldmodel model; leave rest default options , click add
add imports statement top of view
@imports perpetuumsoft.knockout
create knockout context in code section
dim ko = html.createknockoutcontext()
define view , apply model under h2 tag
<p>first name: @ko.html.textbox(function(m) m.firstname)</p>
<p>last name: @ko.html.textbox(function(m) m.lastname)</p>
<h2>hello, @ko.html.span(function(m) m.fullname)!</h2>@ko.apply(model)
now if compile , execute application , call helloworld controller (localhost:nnnnn/helloworld) notimplementedexception raised on line ko.apply(model).
if repeat steps above when creating asp.net mvc project c#, works expected.
please try this
in vb.net syntax of code changed.
protected overridable function visitmethodcall(m methodcallexpression) string if gettype(expression).isassignablefrom(m.method.returntype) return visitmemberaccess(m.[object], m.method.name) end if throw new notsupportedexception() end function
i think there's mismatch between assembly contains type iplugin current assembly references.
you should use
typeof (iplugin).module.fullyqualifiedname
and
foreach (var type in t.getinterfaces ()) { console.writeline (type.module.fullyqualifiedname) }
to see particular mismatch is.
Comments
Post a Comment