I have two C#.net projects project 1 and project 2 (names changed) in single solution. I am using Visual Studio 2005. I have added reference of project 2 in project 1 by right clicking and choosing 'Add Reference'. Both projects are of 'Application' project type not Class library type. I have some classes in project 2 which I want to access in project 1. After adding reference I tried to use import namespace of project 2 in project 1 but I guess its not available. Visual studio Intelisense is not showing me the desired namespace.
Can anyone please suggest about how to access namespace and classes across multiple projects?
EDIT :- Is it because there are different assemblies for both the projects?
Thanks
Make sure the classes you want to access are public. So suppose you have the following class in Project 2:
namespace Project2
{
public class Foo { }
}
In Project 1 after you've referenced Project 2 you can use this class:
namespace Project1
{
using Project2;
public class Bar
{
public Bar()
{
Foo foo = new Foo();
}
}
}
Import is a Visual Basic.NET term. In C# you would use using.
Related
I am trying to make a base/abstract class that contains an Azure Function, which I can use from within a different project when it inherits from the base, but can't seem to get the functions from within the base class of the first project to appear.
(Currently using Azure Functions v3 in .Net Core 3.1 in VS2019)
Here's what I have tried...
Base class in project 1:
public class BaseClass
{
[FunctionName("Function1")]
public IActionResult Function1(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
// Function 1 code in here
}
}
New class in project 2:
public class NewClass : BaseClass
{
[FunctionName("Function2")]
public IActionResult Function2(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
// Function 2 code in here
}
}
So, when I run project 2 locally, I thought I should get Function1 and Function2 endpoints ready to be used, but I only get the endpoint for Function2 that is available.
If I run project 1 locally, I get the endpoint for Function 1.
Is this even possible in Azure Functions and, if so, how do I achieve this?
UPDATE - If I move the BaseClass from project 1 into project 2, I get what I want, namely Function 1 and Function 2 at the same time.
UPDATE 2 Repro steps:
Create project 1: Create a new Azure Functions v3 targeting .Net 3.1.
Add an Azure Function using an HTTP trigger.
Run the project. (Basic/demo function 1 should run as expected.)
Create project 2: add another new project in the same solution: Azure Functions v3 targeting .Net 3.1.
Add an Azure Function using an HTTP trigger (to the new project).
Run the new project. (Basic/demo function 2 should run as expected.)
Add a project reference from Project 2 to Project 1.
Make Project 2's class inherit from Project 1's class.
Change each function in each project to NOT be a static class (to allow inheritance to work)
Run Project 2 - only Project 2's functions are displayed.
...then...
Move the Function1.cs file from Project 1 into Project 2 and rename classes/namespaces appropriately and then run the project... both functions are displayed.
One of the work arounds is to call the objects of Base Class in your Derived class i.e..
If your Solution looks like this
Solution
│ Base Project
└───────BaseFunction.cs
│ Derived Project
└───────DerivedFunction.cs
in your DerivedFunction.cs you can use DerivedProject.DerivedFunction.Run()
but the whole point of using Azure functions is to have multiple functions in a single project that will all be deployed at the same time. So, whatever you are doing is expectable (i.e.. Adding The function from Project2 to project1 and using inheritance).
If you are trying to debug both the functions at the same time then you can Add Other Project and using the reference to the existing project but using different ports.
REFERENCES:
Multiple Azure App Function in a project
Multiple function projects using different ports
I think what you are looking is the <FunctionsInDependencies>true</FunctionsInDependencies> property.
More info:
https://stackoverflow.com/a/62800977/6593791
https://www.ericksegaar.com/2021/01/19/discover-precompiled-function-apps/
I'm using Xamarin Forms Prism and I can't use my PCL classes in android project.
common example :
here is the Interface in PCL
namespace BlankApp.Helpers
{
public interface IToast
{
void MakeLongToast(string msg);
}
}
and here is the class in android project
namespace BlankApp2.Droid.DependencyService
{
public class ToastImp : IToast
{
}
}
it can not find IToast Interface reference !
there is a suggest from IDE with this msg : "Reference 'projectname-WebAppMAinModule' and use 'projectname.Helpers.IToast' "
screenshot
which does nothing actually !
I don't have these kind of problems in XamarinForms I face theme while using Prism . Do I forget something in referencing my PCL ?
I'm using
Prism.Forms (7.0.0.396)
Xamarin.Forms (2.5.0.122203)
also there are my project dependencies
here
You should be able to implement PCL interfaces and use its classes, etc. in your platform specific code (Android included).
Use the following steps:
Make sure your Android project is referencing your PCL.
Delete your Android obj & bin folders.
Recompile your PCL
After recompiling your PCL, recompile your Android project
See if it recognizes your interface now.
If the above doesn't work, then as one last option is:
Close the solution
Re-open the solution
Both of these typically work when your project won't recognize a newly created Interface.
I'm creating native extension with Flex 3.6. Coded native side then created Flex Library Project and then create .ane file. Finally imported .ane file to myFlex Project. Here is the problem I had. While I'm debugging app, "1046: Type was not found or was not a compile-time constant: ExtensionContext" error occurs. Attached the Library project .as class .
Thanks in Advance
package com.extension.samples
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.external.ExtensionContext;
public class NetworkConnectionANE extends EventDispatcher
{
public var _extContext : ExtensionContext;
public function NetworkConnectionANE(target:IEventDispatcher=null)
{
_extContext = ExtensionContext.createExtensionContext("com.extension.samples.NetworkConnectionANE", null);
super(target);
}
public function Connect(path:String):int
{
return _extContext.call("nativeFunc", path);
}
public function dispose():void
{
_extContext.dispose();
}
}
}
Edit:
I tried to use .swc file that created from library project in another Flex Desktop app, but the same error
Also tried with _extContext = ExtensionContext.createExtensionContext("com.extension.samples.NetworkConnectionANE","");
Edit: The problem about Flex SDK,no problem in SDK 4.6. Now the question is, How to use Extension in lib project in Flex 3.6 SDK ?
Right click on the project in flash builder goto properties of project and add air libraries in the flex library compiler.
I had the same problem but it was resolved in the following way:
File > New > Flex Library Project
Check the "Include Adobe AIR Libraries" option
As I know ExtensionContext.createExtensionContext() can be null in these cases:
The call is not in an .ane file. You cannot call this from a .swc or a .swf file. In other words it needs to be compiled to an .ane file before calling it.
You try to use the extension in a platform, that is not supported by the extension. For example you try to use an iOS extension on PC.
The ID for the extension does not exists. The extension ID must be the same, as the one you specify in the extension.xml like:
<extension xmlns="http://ns.adobe.com/air/extension/3.5">
<id>com.extension.samples.NetworkConnectionANE</id>
<versionNumber>0.0.1</versionNumber>
....
btw you dont need to set the second parameter of the ExtensionContext.createExtensionContext call, unless you want to specify OS-specific APIs (I havent even seen apps, that do this)
I'm using the .NET 4 framework, and I have a static class with static functions in an asp.net web application.
I have a second class library project. The class library project wants to call the static method in the web application. Intellisense works, but then the compiler reports that
"The name [MyClassName] does not exist in the current context".
Can I make this call, or this not allowed?
PS, the static class is in the /App_Code folder.
Thanks!
Is it not possible to refactor the class out of the web project? Referencing a web project from a class library sounds awkward. If your class does not contain web-specific code then you could pop it into that other class library you mention or create a new one. Should it reference web-specific libraries something like MyProject.MyLib.Web could do the trick.
You need to add a reference to the project containing the class you want to access.
You need to ensure that you are using the full name of the class (including the namespace).
Alternatively add a using directive with the namespace to your code file.
If your target framework is .Net Framework 4.0 Client Profile change it to .NET Framework 4 and rebuild the solution.
I just converted UberSite, a vb.net web site to a web application. I get run-time errors saying that there is no such thing as type foo. When I drill down to the page in the code-view, it gives me an error-correction suggestion: import namespace UberSite.
If I create a new web application and define foo there, there is no need to import any namespace to use foo in the new application.
How can this be? Why does my web application seemingly need to import its own namespace?
Did you look at the namespace that is defined in your foo class? It could be that it falls into a different namespace than your web application project, even though the class is included as part of that project in VS. For example:
namespace MySuperCoolNameSpace.Lib
{
public class Foo
{
public Foo()
{
}
}
}