Namespace not found error when trying to compile - c#

Edit: Changing the class name or namespace name so that the namespace and class don't have the same name doesn't fix this issue.
I have this super simple code:
Program.cs:
using System;
using CodeCleaner;
class Program
{
private static void Main(string[] args)
{
Console.WriteLine("DocTypeChecker instantiated");
var codeCleaner = new CodeCleaner.CodeCleaner();
}
}
CodeCleaner.cs:
using System;
namespace CodeCleaner
{
public class CodeCleaner
{
public CodeCleaner()
{
Console.WriteLine("CodeCleaner instantiated");
}
}
}
This produces the following error when I try to compile when I run $ csc Program.cs:
Program.cs(4,7): error CS0246: The type or namespace name 'CodeCleaner' could not be found (are you missing a using directive or an assembly reference?).
I'm definitely not missing a using directive for CodeCleaner, but what it means with assembly reference I have no idea. Other solutions on the web didn't help me in this case. Anyone know the issue here?

Running csc Program.cs won't compile CodeCleaner.cs, so your assembly will be missing the CodeCleaner class and namespace. Using csc Program.cs CodeCleaner.cs should do the trick.

Related

Blazor namespace Interop does not extist in the namespace

Where do I find the assembly reference and how can I add it?
Error Description:
CS0234 The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.AspNetCore.Blazor.Browser' (are you missing an assembly reference?)
CS0103 The name 'RegisteredFunction' does not exist in the current context Phoneword.Client
I have a small Blazor project which I would like to run again after some time. But it seems I've deleteted the reference or something else is broken.
Edit I:
Blazor: 0.5.1
Target framework: .NET Standart 2.0
'RegisteredFunction' does not exist anymore.
This is how you define a function in a JavaScript file:
window.exampleJsFunctions = {
showPrompt: function (message) {
return prompt(message, 'Type anything here');
}
};
And this is how you call the function from your Blazor code:
using Microsoft.JSInterop;
public class ExampleJsInterop
{
public static Task<string> Prompt(string message)
{
// Implemented in exampleJsInterop.js
return JSRuntime.InvokeAsync<string>(
"exampleJsFunctions.showPrompt",
message);
}
}

Xamarin Android - Type or namespace "Context" could not be found

I'm following this Xamarin tutorial. Visual Studio throws an error when I use the "Context" class in my Android project. Shouldn't this class be included in my Android app by default?
Also, I defined an interface named "IStreamLoader" in a Portable Class Library called "Portable", and added a reference to "Portable" in my Android project. But referencing "IStreamLoader" in my Android project throws another error.
Are these two errors related?
Errors
CS0246 The type or namespace name 'IStreamLoader' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Context' could not be found (are you missing a using directive or an assembly reference?)
CS0246 The type or namespace name 'Context' could not be found (are you missing a using directive or an assembly reference?)
MyTunes.Droid\MainActivity.cs
using System.Linq;
using Android.App;
using Android.OS;
namespace MyTunes
{
[Activity(Label = "My Tunes", MainLauncher = true)]
public class MainActivity : ListActivity
{
protected async override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var data = await SongLoader.Load();
ListAdapter = new ListAdapter<Song>() {
DataSource = data.ToList(),
TextProc = s => s.Name,
DetailTextProc = s => s.Artist + " - " + s.Album
};
}
}
public class StreamLoader : IStreamLoader
{
private readonly Context context;
public StreamLoader(Context context)
{
this.context = context;
}
public Stream GetStreamForFilename(string filename)
{
return context.Assets.Open(filename);
}
}
}
Portable\IStreamLoader.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Portable
{
public interface IStreamLoader
{
System.IO.Stream GetStreamForFilename(string filename);
}
}
Try this :
using Android.Content;

Using Topshelf and Quartz.NET

I'm having problems setting up a basic Quartz.NET and Topshelf integration.
Errors appear when accessing ScheduleQuartzJob:
Error 1 Delegate 'System.Func<ServiceTest.MyService>' does not take 1 arguments
Error 2 Not all code paths return a value in lambda expression of type 'System.Func<Topshelf.Runtime.HostSettings,ServiceTest.MyService>'
Error 3 'Topshelf.Runtime.HostSettings' does not contain a definition for 'ConstructUsing' and the best extension method overload 'Topshelf.ServiceConfiguratorExtensions.ConstructUsing<T>(Topshelf.ServiceConfigurators.ServiceConfigurator<T>, System.Func<T>)' has some invalid arguments
Error 4 Instance argument: cannot convert from 'Topshelf.Runtime.HostSettings' to 'Topshelf.ServiceConfigurators.ServiceConfigurator<ServiceTest.MyService>'
Error 5 'Topshelf.Runtime.HostSettings' does not contain a definition for 'WhenStarted' and no extension method 'WhenStarted' accepting a first argument of type 'Topshelf.Runtime.HostSettings' could be found (are you missing a using directive or an assembly reference?)
Error 6 'Topshelf.Runtime.HostSettings' does not contain a definition for 'WhenStopped' and no extension method 'WhenStopped' accepting a first argument of type 'Topshelf.Runtime.HostSettings' could be found (are you missing a using directive or an assembly reference?)
Error 7 'Topshelf.ServiceConfigurators.ServiceConfigurator<ServiceTest.MyService>' does not contain a definition for 'ScheduleQuartzJob' and no extension method 'ScheduleQuartzJob' accepting a first argument of type 'Topshelf.ServiceConfigurators.ServiceConfigurator<ServiceTest.MyService>' could be found (are you missing a using directive or an assembly reference?)
I think I am missing something obvious here...
Side question: Is there a simpler way to set up a Quartz/Topshelf configuration?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using NLog;
using Quartz;
using Quartz.Impl;
using Common.Logging.Configuration;
using Common.Logging.NLog;
using Topshelf;
namespace ServiceTest
{
public class MyService
{
public bool Start(HostControl control)
{
return true;
}
public bool Stop(HostControl control)
{
return true;
}
}
public class Program
{
private static Logger log = LogManager.GetCurrentClassLogger();
public static void Main(string[] args)
{
var config = new NameValueCollection();
var adaptor = new NLogLoggerFactoryAdapter(config);
Common.Logging.LogManager.Adapter = adaptor;
HostFactory.Run(x =>
{
x.Service<MyService>(sc =>
{
sc.ConstructUsing(() => new MyService());
sc.WhenStarted((service, control) => service.Start(control));
sc.WhenStopped((service, control) => service.Stop(control));
sc.ScheduleQuartzJob(q =>
q.WithJob(() =>
JobBuilder.Create<MyJob>().Build())
.AddTrigger(() => TriggerBuilder.Create()
.WithSimpleSchedule(b => b
.WithIntervalInSeconds(10)
.RepeatForever())
.Build()));
});
x.RunAsLocalSystem()
.DependsOnEventLog()
.StartAutomatically()
.EnableServiceRecovery(rc => rc.RestartService(1));
x.SetDescription("Checker Service");
x.SetDisplayName("Checker Service");
x.SetServiceName("CheckerService");
x.UseNLog();
});
}
}
public class MyJob : IJob
{
private static Logger log = LogManager.GetCurrentClassLogger();
public void Execute(IJobExecutionContext context)
{
log.Info("It is {0} and all is well", DateTime.UtcNow);
}
}
}
Needed to add a reference to Topshelf.Quartz!
I knew it was something stupid and simple.

C# MVC7 DNX5 MSSQL

Got a Noob question. I am trying to write a C# MVC Application to connect to an MS SQL DB using the Entity Framework. But I am getting the following error.
Severity Code Description Project File Line Suppression State
Error CS1061 'DatabaseFacade' does not contain a definition for 'SqlQuery' and no extension method 'SqlQuery' accepting a first argument of type 'DatabaseFacade' could be found (are you missing a using directive or an assembly reference?) HAPI.DNX 4.5.1, HAPI.DNX Core 5.0
My Code is as follows
DB Context Class which flags no issues.
using Microsoft.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Something.Models
{
public class RulesDbContext: DbContext
{
public DbSet<Rules> Rules { get; set; }
}
}
Calling Class with errors on the Sql Statements highlighted in bold
using System.Collections.Generic;
using System.Linq;
using Microsoft.Data.Entity;
namespace Something.Models
{
public class ReadRules
{
private RulesDbContext db = new RulesDbContext();
private void Rules()
{
List<Rules> rulesMeta = db.Database.**SqlQuery**<Rules>("GetRuleMetaData #deviceID",
new **SqlParameter**("deviceID", deviceID)).ToList();
}
}
}

The type of namespace name could not be found (are you missing a using directive or an assembly reference?)

I have this class:
using System;
using System.Web.Mvc;
using System.Data;
using BLL;
namespace LicenseManager.Controllers
{
public class ValidationController : BaseController
{
public ActionResult Default()
{
return View("Default");
}
[HttpPost]
public JsonResult ClearInstallation(FormCollection form)
{
var jr = new JsonResult();
try
{
var licMgr = new BLL.LicManager();
licMgr.ClearInstall(form["regKey"], form["checkKey"]);
}
catch (Exception exc)
{
jr = Json(new { success = "false", error = exc.Message });
}
return jr;
}
}
}
When I try to rebuild or debug I receive the error: The type of namespace name 'BLL' could not be found (are you missing a using directive or an assembly reference?)
I can see that it is referenced:
The intellisense works, and I don't have any errors, until I try to rebuild or compile. I know it exists, and it finds it for intellisense purposes, so why won't it allow me to rebuild or compile?
I have tried:
cleaning the solution
rebuilding
clearing the reference and re-adding it
What else can I try?
UPDATE
If you get this error, make sure you read the output. It contained the solution for me.
I had a similar problem when the referenced project was using a different .net framework. Make sure the project you are building and the project you have referenced are using the same framework.
You can verify/change the framework in properties/application/target framework

Categories