Could not add system.web.routing in class library - asp.net-mvc-4

I want to create a class library for an MVC 4 web application.I created class library project in same solution and write classes and other stuff in class library.I added the reference System .Web.Routing in my class library project. But when i tried to use
System.Web.Routing in project that displays following error
The type or namespace Routing does not exist in the namespace System.Web
How to add this in my class library project?

Related

How can I get ApplicationPartAttribute within .net5 class library?

The task is not practical, it's just learning experiment.
I have .net5 app (which essentially is asp .net core app) which references onto neighboring project "WebControllers" which contains only Controller class.
WebControllers is .net5 class library into which I added reference to Microsoft.AspNetCore.Mvc.Core package. This package allows to create of working Controller object which is discovered by asp .net core infrastructure and which properly handles http requests.
Now I want inside my WebController objec create variable of ApplicationPartAttribute type. I tried doing this like that:
var aaa = new Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("asd");
But Visual studio says to me that it don't know ApplicationPartAttribute class and it doesn't offer to use some namespace or add some package.
Let's go to the MSDN. MSDN about this type for .NET5 says:
Namespace: Microsoft.AspNetCore.Mvc.ApplicationParts
Assembly: Microsoft.AspNetCore.Mvc.Core.dll
Package: Microsoft.AspNetCore.App.Ref v5.0.0
Okay, let's try to install this package. Next errors are occured:
NU1213 The package Microsoft.AspNetCore.App.Ref 5.0.0 has a package
type DotnetPlatform that is incompatible with this project.
Package 'Microsoft.AspNetCore.App.Ref 5.0.0' has a package type
'DotnetPlatform' that is not supported by project 'WebControllers'
Why these errors are occured is unclear to me because both projects are .net5 projects and Microsoft.AspNetCore.App.Ref v5.0.0 is designed for .NET 5.
The question is: how can I use ApplicationPartAttribute in .net5 class library?
Add this code in your xxx.csproj file
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>

C# CLR Excecption "BadImageFormatException: Could not load file or assembly"

I am using VS 2019 Version 16.8.2
I referred a "CLR Class Library(.NET Core)" project in my "WPF App (.NET)" project and i met a exception:
BadImageFormatException: Could not load file or assembly 'LibCLR, Version=1.0.7646.21580, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
Let me first talk about how I did it.
Create a "WPF App (.NET)" project "TestCLR"
Add a new "CLR Class Library(.NET Core)" project "LibCLR" in this solution
The "common language runtime support" setting of "LibCLR"
Target "TestCLR" to ".NET 5.0"
"LibCLR.h" created automatically in project "LibCLR" and codes was inside
#pragma once
using namespace System;
namespace LibCLR {
public ref class Class1
{
// TODO: Add your methods for this class here.
};
}
Add "new LibCLR.Class1();" in MainWindow.xaml.cs in project "TestCLR"
using System.Windows;
namespace TestCLR {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
new LibCLR.Class1();
}
}
}
Rebuild All and debug, then i met exception
Then i change the solution platform to x64 or x84, the exception were the same.
It works well if i choice "WPF App (.NET Framework)" for "TestCLR" in step 1 and "CLR Class Library(.NET Framework)" for "LibCLR" in step 2
Why did not it work?
Can not i use a "CLR Class Library(.NET)" project as a project reference in a "WPF App (.NET Core)" project?
How can i solve this problem?
You should change Platform target to "X86" here
The most common answer is changing between x86 and x64 targets. In a comment to your original question, here, you mentioned that you tried that and it didn't work for you. So, I have a suggestion. You are building a WPF project, and targeting dotnet 5.0. Dotnet 5.0 is OS-agnostic. WPF is OS-specific. It needs Windows.
Try using an OS-specific Target Framework Moniker. Open the .csproj file of both projects. Try setting both projects to <TargetFramework>net5.0-windows</TargetFramework>
Clean solution, rebuild, and test.
We've got a solution here that is dependent on Windows. We shouldn't have to, but let's try explicitly targeting it. Especially that C++ project.
More reading
NET 5: Merging .NET Core and .NET Standard with New Target Framework Monikers (TFMs)
New templates Targeting .NET 5.0
Cannot compile WPF applications targeting .NET 5

Read app configfile entry in multiple projects which is in the common class library

I have a common class library project which has code to read entry from the app config file which is in the same class library.
Now, i would like to read the entry in multiple other projects by instantiating the class library .
Note:- don't suggest to add the App.Config file to the main solution and not in the class library project :-)which know. But as stated above my requirement is different.

Appcelerator Titanium developing iOS native module - having more than one module inside the package

If I create a new module project than the templates comes with a default named convention class that inherits from TiModule.
I would like my module to encapsulate more than one module inside it, so I've created another class that inherits TiModule with the name or MyNewModuls.m
Everything compiles and built, but how can I call methods I've created on that module from javascript code? When I require my module, only methods from the original module file that inherits TiModule exist.
You cannot add multiple module subclasses in side a module package. Please check the Titanium Module documentation. In that the above scenario is clearly mentioned a module cannot have multiple module classes.

How to setup ninject when injection and Module binding (nInjectModule) into separate assembly

Following is project structure:
MVC 4 application
1) Project is for MVC having controller has injected interfaces.
2) interfaces are existed into this application.
Manager library project.
1) Project contain refernece of MVC application.
2) Implementation of each interfaces into this assembly.
3) NinjectMOdule is existed into this project where binded interface with related manager class.
PROBLEM: unable to get injected classes into web application.
it gives following error:
Error No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency ILeadInformation into parameter leadInformation of constructor of type HomeController
1) Request for HomeController
Usually in the "root" project which manages the kernel you need to load all the modules. This has to be done during initialization of the application i.E. before the application relies on the binding being there.
Let's say the module which binds the ILeadInformation is called LeadModule. It would look like:
IKernel.Load<LeadModule>();
EDIT:
For your concrete scenario, you have your MVCApplication Assembly which contains the application and some interfaces and you have your Manager assembly, which references the MVCApplication assembly, like so:
Now you ought to place the Composition Root in the MVCApplication assembly. But, uh no, you can't reference the Manager assembly, since that would lead to a circular dependency.
So we got to fix this. We need to move the interfaces into a new assembly. And adjust the references so it will look like: