I have a project written in MVC2 and VB.NET. I use a lot of htmlhelper extension methods, and I have them all in a public module. They work just fine, and I can compile and run my project. I reference the namespace they are in with this:
<%# Import Namespace="MyProject.WebUI.Extensions" %>
So, again, they work great, my project runs and compiles without a hitch.
The problem is that each one of these extension methods is shown as an error:
Error 33 'TabbedMenu' is not a member of 'System.Web.Mvc.HtmlHelper(Of Object)'. C:\Projects\MyProject\MyProject.WebUI\Views\Shared\Site.Master 23 21 MyProject.WebUI
This doesn't prevent the project from compiling and running, it just creates an error, which is annoying. I've tried looking for solutions, but all of the solutions I've found were for projects that don't compile, all with simple solutions like referencing the right namespace or making sure your module is declared public. Any thoughts?
Have you included an import statement in your site.Master to include the extensions class where your extensions are defined. Also I assume your extension class is a public static class with public static methods defined?
Also check this out if you haven't already, it may be related to what you are after.
How do I use an extension method in an ASP.NET MVC View?
You need to import the namespace where you have placed your extension. And since it is a bit annoying that this problem shows up no sooner than in runtime, you can enable view compilation to have the compiler detect the problem. I should warn you that compiling the views is a time consuming operation though.
Related
I am creating a custom asp.net.identity provider in a separate assembly in order to use it from two different web api 2 projects.
I took the default vs2013 template for a web api project as a guide and so far I have implement the required classes.
In the separate assembly I am using a user manager class derived from Microsoft.AspNet.Identity.UserManager(Of T) class.
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
Now I want to implement the create shared function in order to use as a callback in the CreatePerOwinContext function. According to the template, I am declaring it like this:
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
... Class Implementation ...
Public Shared Function Create(options As IdentityFactoryOptions(Of EzeUserManager), context As IOwinContext)
Dim Result As New EzeUserManager(New EzeIdentityUserStore(context.Get(Of EzeLDAPContext)()))
The problem is that
context.Get(Of EzeLDAPContext)()
fails because it requires a key.
From the template I can see that the get method which doesn't require a key is an extension defined in Microsoft.AspNet.Identity.Owin.OwinContextExtensions which I have already installed and referenced through nuget and imported it in the class.
But it doesn't work.
I found that the key is actually the type name of the class so probably I can overcome this problem, however I didn't try it yet because I really want to make the extensions to work.
The question is: Am I missing something here?
Notes: The project in question is a Class Library targeting .NET 4.5.1 with the following references:
Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Security.OAuth
Newtonsoft.Json
Owin
As I explained in the question, I was using the template generated by VS as a guide. During the implementation process of my project, I had update the nuget packages several times but only in my project not in the template project (same solution) since I was going to deleted it afterwards. This resulted the two projects to reference two different versions of the required assemblies.
I don't know how exactly and why this "multi" reference caused this problem but once I updated the template project's nuget packages the problem was resolved.
I hope this helps someone with a similar issue.
I have a scenario where I need to use a plugin as well as a static library into my xcode project. The plugin will be dynamically loaded into the system. Now, the static library is also getting used in creation of the plugin.
While executing my project I am getting a warning saying :
Class A is getting referenced from /staticLibraryPath and plugin. One of them will be used.
Please let me know, how to resolve the warning or a better way of implementing the scenario.
The issue is a name class of the two ClassA types found in both plugin and library
I assume you have control over the source of either plugin / library.
.. rename Class A in one instance to make the names not clash -- I don't think there is another way to get rid of the warning/error
I have a Helper class in my project that I use to help me develop the application. How do I NOT include this class in the final build when I take the application in production?
I still want the people who are going to do the maintenance to have access to it though.
So the behavior I'm looking for would be for the program to function normally while I'm developing it in Visual studio with the debug configurations. But if I build it with the release configurations, I would get an error for calls to an unknown member (supposing I didn't remove the calls to the Helper).
Sort of the same kind of behavior we have with tests.
An even better solution would not have me remove the calls to the Helper in the code.
Any way to do that?
Please comment if the question is unclear.
Use the ConditionalAttribute on the methods in the class.
Passing in DEBUG will mean that only when the DEBUG symbol is defined will the class compile.
Applying ConditionalAttribute to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with ConditionalAttribute is defined.
<ConditionalAttribute("DEBUG")> _
Sub Method1(x As Integer)
Console.WriteLine("DEBUG is defined")
End Sub
I created a new Metro Split App in C++ using VS2012 on Win8 (both RC). Everything compiled and worked out of the box. I then changed went through and changed the generated namespaces to my own. After some trials and tribulations, I got everything to compile with no warnings, errors, nor messages. The app (as it comes in the project template) runs fine.
However, if I try to edit either of the generated xaml files (ItemsPage.xaml or SplitPage.xaml) I get a "Markup error" on the first line:
The name "LayoutAwarePage" does not exist in the namespace "using:A.B.Product.Client.Common".
The definition of the class is:
namespace A{ namespace B { namespace Product { namespace Client { namespace Common
The code compiles fine, and runs fine. This only happens in design mode.
UPDATE: I added a new xaml file and (after fixing up the namespaces again) everything worked.
Please let me know if any additional information is needed.
The name of the WinMD file produced by your project must be some prefix of the namespaces in which the public WinRT types are defined. Given that your type is in the A.B.Product.Client.Common namespace , the WinMD file must have one of the following names:
A.winmd
A.B.winmd
A.B.Product.winmd
A.B.Product.Client.winmd
A.B.Product.Client.Common.winmd
The public types must also be defined in the WinMD file with the longest prefix that matches the namespace. So, if you have both A.winmd and A.B.winmd, the type A.B.MyClass must be defined in A.B.winmd.
So, why does your code work at runtime but not in the designer? The naming rules for public types only apply to types defined in Windows Runtime components (for C++, DLL files), not for applications (EXEs).
However, to be able to instantiate your user-defined types (including LayoutAwarePage), the designer will load your project's EXE as a DLL, so the naming rules must be followed.
I had a similar bug, but then I closed VS, deleted the .suo, and reloaded the project and everything worked just fine.
I have a class (e.g. MksMath) written in IronPython using SharpDevelop 3.2. After compiling it for class library, it produced the following output:
IronPython.dll
IronPython.Modules.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.dll
Microsoft.Scripting.ExtensionAttribute.dll
mksmath.dll
If I try to add reference to all above dll and import "MksMath", I am unable to access it. The vbc is throwing the following error:
Namespace or type specified in the Imports 'MksMath' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
I am new to IronPython. Kindly advise how to use this class in my vb.net code?
I post here my answer that I posted to IronPythopn mailing list :-)
You cannot use mksmath.dll directly from VB (see Compiling Python code into an assembly) so you have to host IronPython engine in your VB app and use mksmath.dll from the engine. See Using Compiled Python Classes from .NET/CSharp IP 2.6 for example (in C#).
Here is a link that I think may solve the issue. http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx