I'm getting really stuck trying to refer to methods/classes in a project imported into a blank project. The exact steps to recreate this are as follows
Download and Extract into a temp folder http://mywsat.codeplex.com/
Create a new project in VS - Asp.Net Empty Web Application .NET 3.5 named WebApplication1
Copy all files from MYWSAT35 folder across to the new project
In VS solution explorer, select Show all files
If you now build and run the project runs fine with no errors.
5 In VS solution explorer, for all of the imported files right click and select Include in Project
Now try rebuilding the project I get the error
The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
GetAdminMasterPage.cs is located in WebApplication1\App_Code\class\GetAdminMasterPage.cs and looks like this
#region using references
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Caching;
using System.Web.UI;
#endregion
/// <summary>
/// Gets the MasterPage for the user selected Admin Theme.
/// </summary>
public class GetAdminMasterPage : System.Web.UI.Page
{
#region Get Admin MasterPage
protected override void OnPreInit(EventArgs e)
{
if (Cache["cachedAdminMaster"] == null)
{
GetDefaultMasterPage();
}
else
{
string loadMasterFromCache = Cache["cachedAdminMaster"].ToString();
Page.MasterPageFile = loadMasterFromCache;
}
}
private void GetDefaultMasterPage()
{
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbMyCMSConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("sp_admin_SelectMasterPage", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.SingleResult);
if (myReader.Read())
{
string masterPageFileName = myReader["ThemeUrl"] as string;
Cache.Insert("cachedAdminMaster", masterPageFileName, null, DateTime.Now.AddSeconds(300), System.Web.Caching.Cache.NoSlidingExpiration);
Page.MasterPageFile = masterPageFileName;
}
myReader.Close();
con.Close();
con.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
#endregion
}
An example of one of the methods that now gives an error is
using System;
public partial class admin_admin_edit_css : GetAdminMasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
//gives error The type or namespace name 'GetAdminMasterPage' could not be found
(are you missing a using directive or an assembly reference?)
So I know I must refer to GetAdminMasterPage with Using xxxxxx; but just can't figure out the correct syntax.
Firstly why does the error only occur when I select "Include In Project" and not when just copied?
Secondly, how do I fix the error with the correct path to the GetAdminMasterPage?
After opening the project as a web site, right-click the project and choose "Convert to Web Application". The result of the conversion is what you'll want to move to your blank project, or perhaps you'll want to leave the changes in place.
You have to open the project as a web site.
If you are using VS2010, then it will prompt you for upgrade to .net 4.0. You can choose no.
But if you are opening in VS2012, it will open it with no prompts.
Both will build successfully.
Note: you do not create a new project.
1.Copy the MYWSAT35 folder in a drive (for example: d:\MYWSAT35)
2.in Visual Studio go to File -> Open web site
3.select d:\MYWSAT35 and click on open
4.press F5 key to run application
Related
It can be seen and compiled inside the same file it is in inside the same project, the file is called default.aspx.cs.
However when I try to include the namespace in another file of the same project using the using DBConnStrings; statement -> I keep getting the compiler error "The type or namespace name 'DBConnStrings' could not be found".
The Code in the file which compiles called default.aspx.cs is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using DBConnStrings;
namespace DBConnStrings
{
public class GlobalStrings
{
public static string carSalesDBConnString =
ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
}
}
public void BindManu()
{
SqlConnection conn = new
SqlConnection(GlobalStrings.carSalesDBConnString); // Connect to Carsales database
conn.Open();
// .....
}
The other files can not see this namespace although they are in the same project.
How do I make them see it?
First of all, I'd suggest to put the method BindManu into the class, because I can't imagine this would work like that.
But to your problem: You have to specify the whole namespace. That means, if the file with the DBConnStrings namespace is in the folder test, you have to use using test.DBConnStrings to import the namespace. You should name the namespace like that as well to avoid confusion (namespace test.DBConnStrings).
But you actually don't have to specify the whole path, just the path within the project. That means, if your class is in C:\Users\Foo\Documents\Visual Studio 2017\Projects\BlaProject\DirectoryA\DirectoryB\MyClass with the project located in C:\Users\Foo\Documents\Visual Studio 2017\Projects\BlaProject, your namespace would be BlaProject.DirectoryA.DirectoryB. If the file your using isn't in your project folder, then you have to add a reference and use the path within the other project as above (but with another project name, obviously). If you want to add references, open the Solution Explorer, right click onto References, select add Reference, and select the reference to the project.
If you don't want to struggle with all that you can let vs do it for you. Simply type in the class you want from the other namespace, it will be marked as an error, click onto the lightbulb and select something like add using reference.
Furthermore, if you want to add a class to your project, don't do it with the explorer - simply right click onto the folder from your project you want to add the class to in your Solution Explorer, select Add, then New Item. In the popup select class and type in your name for the class. That's it!
I'm trying to get SQLite running in Visual Studio 2012 for C#.
However after going through a set of tutorials I still get the error DllNotFoundException for the SQLite.Interop.dll.
This is the full error I receive:
Unable to load DLL 'SQLite.Interop.dll': The specified path is
invalid. (Exception from HRESULT: 0x800700A1)
I have created a reference for the System.Data.SQLite.dll. Now I found that I have to add the SQLite.Interop.dll file into my project folder but I still get this error.
Oh and BTW, this is my code, if anyone is interested:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
namespace SQLiteWinFormCS
{
public partial class Form1 : Form
{
private SQLiteConnection _sqlCon;
private SQLiteCommand _sqlCmd;
private SQLiteDataAdapter _db;
private DataSet _ds = new DataSet();
private DataTable _dt = new DataTable();
private string _dbPath = String.Empty;
public Form1()
{
InitializeComponent();
}
private void uiOpenDB_Click(object sender, EventArgs e)
{
Console(String.Format("You clicked {0}.", ((Button)sender).Name));
this._dbPath = uiDatabaseFilepath.Text;
Console("Filepath to DB = " + this._dbPath);
Console("Attempting to open DB connection...");
this._sqlCon = new SQLiteConnection(String.Format("Data Source={0};", #"\\Some-PC\ISC\Databases\testdbs\test.db3")); // << ERROR
Console("DB connection succesfull!");
}
private void Console(string text)
{
uiConsoleOutput.AppendText(text);
uiConsoleOutput.ScrollToCaret();
}
}
}
Can anyone help me get this thing working?
Thanks in advance.
Copy the SQLite.Interop.dll file into your debug folder.
For example "Projects\sqlite test18\sqlite test18\bin\Debug" place it here.
And dont add the Interop as a reference.
Add only these references
System.Data.SQLite
System.Data.SQLite.EF6
System.Data.SQLite.EF6
This solved my problem.
And I was using Sqlite x86 under x64 OS.
Dohh...
I was probably using a wrong System.Data.SQLite.dll.
For anyone who is interested you can find the new .dll file I downloaded here:
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
I needed the .dll for the 4.5 Framework (x86); I clicked the first download link.
Also I am using just the System.Data.SQLite.dll, no other files!
Hope this answer helps someone else. :-)
When I run a c# application through Visual Studio 2010, where R is integrated, I get the error: The program can't start because Rlapack.dll is missing from your computer. Try reinstalling the program to fix this problem.
I tried reinstalling the program but it did not work.
I also tried putting it in the folder that has the Matrix in it but it did not work. This solution was suggested in StackOverflow Q.
I am running 64-bit Windows 7! The application is 32-bit.
There are two dll's. One in a folder called i386, and another one in the folder x64.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RDotNet;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string dlldir = #"D:\Program Files\R-2.15.0\bin\i386";
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(dlldir);
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch
{
MessageBox.Show(#"Unable to find R installation's \bin\i386 folder.
Press OK to attempt to locate it.");
}
}
}
}
}
I realize this has been answered, but that was back in 2012. For anyone still having this problem with R version 3.4.3 or later in 2018, especially while trying to follow the simple example from the r.net home page, below is what I did to fix it:
In your code, before the line REngine engine = REngine.GetInstance();, add this line REngine.SetEnvironmentVariables(#"C:\Program Files\R\R-3.4.3\bin\x64", #"C:\Program Files\R\R-3.4.3");.
right click project, go to build and uncheck "Prefer 32-bit".
copy Rlapack.dll from C:\Program Files\R\R-3.4.3\bin\i386
paste in both C:\Program Files\R\R-3.4.3\library\stats\libs\i386 and C:\Program Files\R\R-3.4.3\library\Matrix\libs\i386
copy Rlapack.dll from C:\Program Files\R\R-3.4.3\bin\x64
paste in both C:\Program Files\R\R-3.4.3\library\stats\libs\x64 and C:\Program Files\R\R-3.4.3\library\Matrix\libs\x64.
Such a pain, but that is what finally got it to work for me.
Here is what I just did and it worked: I put the dll in the bin folder of my application.
Try setting path variable before caling the dll:
var envPath = Environment.GetEnvironmentVariable("PATH");
string s = null;
if (Environment.Is64BitProcess)
s = #"C:\Program Files\R\R-2.15.0\bin\x64";
else
s = #"C:\Program Files\R\R-2.15.0\bin\i386";
Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + s);
Hi every one I am getting the following error: "The name 'ConfigurationManager' does not exist in the current context"
// namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
namespace Database1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string GetConnectionString(string strConnection)
{
//variable to hold our connection string for returning it
string strReturn = "";
//check to see if the user provided a connection string name
//this is for if your application has more than one connection string
if (!string.IsNullOrEmpty(strConnection)) //a connection string name was
{
//get the connection string by the name provided
strReturn = ConfigurationManager.ConnectionStrings[strConnection].ConnectionString;
}
else //no connection string name was provided
{
//get the default connection string
strReturn = ConfigurationManager.ConnectionStrings["YourConnectionName"].ConnectionString;
}
//return the connection string to the calling method
return strReturn;
}
}
}
Have you added a reference to System.Configuration.dll?
You have to add reference to System.Configuration.dll
When you right click and click on the Add reference button
Click .Net tab in the open popup
There you should be able to locate the System.Configuration.dll file
This is the path:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll
also you can add reference to the :System:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.Install.dll
(hope it helps :))
Which version of .NET Framework and Visual Studio are you using?
ConfigurationManager is only available in .NET 2 and above. If you are using .NET Framework 1.x and Visual Studio 2002/2003, you won't be able to use this class at all.
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
Click "Other versions" link in the top of this page and you will see all versions it supports.
I ran into same issue using .Net Core, but using .NET Running Install-Package System.Configuration.ConfigurationManager in Package manager solved it for me.
I am trying to use the lame_enc.dll in my C# .NET website and I am stuck.
I am working with: .NET Framework 3.5 / Visual Web Developer 2008 Express Edition / (Anything else you'd need to know?)
The first thing I did was get the code from C# MP3 Compressor on The Code Project. One thing I noted is that this project/post is from January 2004 (so, it's old)
I put the folders "yeti.mmedia" and "yeti.mp3" in my "App_Code" directory and deleted the "Bin" and "obj" directories within each. Then I tried to build the project. When I got errors I ended up excluding from the project the following files:
yeti.mmedia/AssemblyInfo.cs
yeti.mmedia/EditWaveWriter.cs
yeti.mmedia/EditWaveWriter.resx
yeti.mmedia/InFormatEdit.cs
yeti.mmedia/InFormatEdit.resx
yeti.mmedia/NumericTextBox.cs
yeti.mmedia/NumericTextBox.resx
yeti.mmedia/Win32Functions.cs
yeti.mp3/AssemblyInfo.cs
yeti.mp3/EditMp3Writer.cs
yeti.mp3/EditMp3Writer.resx
These seem to me to be the code files related to the Windows UI (which I don't need sonce I'm doing this on the web).
I also put the file "lame_enc.dll" in the Bin directory.
I created a test page based on the example on the page linked above:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using WaveLib;
using Yeti.MMedia;
using Yeti.MMedia.Mp3;
public partial class Documents : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WaveStream InStr = new WaveStream(Server.MapPath(#"Temp/SomeFile.wav"));
try {
Mp3Writer writer = new Mp3Writer(new FileStream(Server.MapPath(#"Temp/SomeFile.mp3"), FileMode.Create), InStr.Format);
try {
byte[] buff = new byte[writer.OptimalBufferSize];
int read = 0;
while ((read = InStr.Read(buff, 0, buff.Length)) > 0) {
writer.Write(buff, 0, read);
}
}
finally {
writer.Close();
}
}
finally {
InStr.Close();
}
}
}
So, then I load this page and the error I get is:
Unable to load DLL 'Lame_enc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
(I can't add the DLL as a reference in my project because it says "...This is not a COM component.") I have also tried getting the latest and greatest (lame3.98.4) dll and had the same problems. So, I assume there is something different about using this code in a website rather than another type of project. What it is I don't know though.
My guess, having not used LAME, is you have to install in on the box in question. After that, you should be able to use the code project code successfully. If that does not work, it appears Lame_Enc.dll is a native component and you will have to PInvoke methods.