Error after deleting an argument (the "method arguments" error) - c#

I have built a class called "MemoryDB" (whose c'tor takes 6 arguments) and created unit-test for her.
Everything was OK until today - I tried deleting one of the arguments, so they remain 5. Even though (after re-building, saving, re-creating the class MemoryDB, etc.), the unit-test does not recognize the change and the error message appears: TimeTable.DB.MemoryDB does not contain a constructor that takes 5 arguments.
I also tried to re-create the unit-test, but for some reason the automatic c'tor it creates is the old c'tor, with 6 arguments.
Have I deleted the argument in a wrong way? How can I fix this? Do other errors in the project might cause this weird problem?
p.s. here is the old c'tor:
public MemoryDB(List<Grade> allGrades, List<Teacher> allTeachers, ForbiddenHours forbiddenHours, List<Group> allGroups, List<List<Teacher>> staffs, List<List<Group>> parallelGroups)
{
CheckParametersValidation(allGrades, allTeachers, forbiddenHours, allGroups, staffs, parallelGroups);
this.allGrades = allGrades;
this.allTeachers = allTeachers;
this.forbiddenHours = forbiddenHours;
this.allGroups = allGroups;
this.staffs = staffs;
this.parallelGroups = parallelGroups;
}
the new c'tor, after deleting "forbiddenHours":
public MemoryDB(List<Grade> allGrades, List<Teacher> allTeachers, List<Group> allGroups, List<List<Teacher>> staffs, List<List<Group>> parallelGroups)
{
CheckParametersValidation(allGrades, allTeachers, allGroups, staffs, parallelGroups);
this.allGrades = allGrades;
this.allTeachers = allTeachers;
this.allGroups = allGroups;
this.staffs = staffs;
this.parallelGroups = parallelGroups;
}

It is difficult to tell why this happens, but there are certain things to look for when troubleshooting such an issue:
If the library was referenced as a DLL, it is possible that the DLL has not been updated.
If that's the case, rebuild the library - if there are any errors, it has not built. Fix the errors.
Once rebuilt, remove the existing reference and re-add it (not strictly needed, you can simply replace the DLL on the file system)
If the library was referenced as a project:
Make sure the library is building without errors.
It is possible that some caching issues are going on. Restart Visual Studio.

Related

how to solve RDotNet REngine nullreference exception

I am trying to use the REngine.GetInstance() function but I keep getting a null reference exception.
I have tried using another function in REngine just in case the getInstance method was at fault, like REngine.SetEnvironmentVariables(), yet they all return the null reference exception.
I have tried reinstalling the package. I have tried checking the installation path but I couldn't find how the rdotnetlibrary accesses it. I am not even sure the path is related to the problem.
Please help.
Make sure your startupparameters are set up correctly. Since you do not provide us enough information; this is a correct way to get r.net's REngine running:
//...
StartupParameter rinit = new StartupParameter();
rinit.Quiet = true;
rinit.RHome = "C:/Program Files/R/R-3.4.3";
rinit.Interactive = true;
REngine.SetEnvironmentVariables();
rMain = REngine.GetInstance(null, true, rinit);
//...
Make sure you setup RHome to the correct installed R path.
EDIT (thanks to #David M.): In usual cases you only need to pass StartupParameter to GetInstance() if you don't want to have default initialization settings. However, according to the source code comments for the first parameter:
The file name of the library to load, e.g. "R.dll" for Windows. You usually do not need need to provide this optional parameter
In rare cases you need to provide the path of R.dll:
//...
rMain = REngine.GetInstance("C:/Program Files/R/R-3.4.3/bin/x64/R.dll", true, rinit);
//...
I've had the same issue using version 3.5.0
a call to "REngine.GetInstance" would result in 'Object reference not set to an instance of an object'
I downgraded to 3.4.0 and I'm not getting that error anymore.
When we upgraded R from 3.4 to 3.5, we got that exact error. We downgraded back to 3.4 and moved on.
As other answers have pointed out, this appears to be an issue relating to R 3.5 and above. I also managed to work around this by downloading R 3.4.4 and having both versions run concurrently, using Shique's solution.
For those unable to downgrade their R, it looks like jmp75 has been working on a fix, and there is a WIP branch available at https://github.com/StatTag/rdotnet/tree/r_3_5_0

DLL dependency not getting copied issue

I'm using VS2015 and have two projects where the child project references DapperExtensions (X--> Y--> DapperExtensions).
Now DapperExtensions seems to have implicit dependency on Dapper.
When I try and use code from Y in X, I get an error regarding Dapper.dll missing.
It seems with dlls being copied to project X debug folder, only DapperExtensions.dll is getting copied but Dapper.dll isn't.
Presumably related to the direct dependency issue identified in stackoverflow already :
Dll not copying to bin folder
So I created some dummy code to reference an arbitrary reference from Dapper but this doesn't seem to lead to the DLL getting copied as per existing suggestions in stackoverflow:
public static void Dummy()
{
Action<Type> noop = _ => { };
var dummy = typeof(Dapper.DbString);
noop(dummy);
}
The only thing I guess left is to add dappper dll reference directly to ProjectX which I really want to avoid.
Any ideas why the dummy reference thing doesn't work?

Table has no (public) columns only on real device

I have the simplest of apps that I thought I would try on my device before I got too engrossed. However, I am getting the strangest error message when I run it on my iPhone (as apposed to the the emulator on my macbook).
Table has no (public) columns .
I am using the SQLite.Net PCL and I have built it from git hub as I had some problems with it not having the platform dlls for IOS otherwise.
Relevant code.
In my models I have this:
public class Setting
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
[Indexed]
public string Key { get; set; }
public string Value { get; set; }
}
The code that throws this error message is the simple:
using (SQLiteConnection db = GetCon ()) {
db.CreateTable<Setting> ();
}
but in my opinion the strangest thing is that this code works fine on the emulator but crashes the application on the iphone itself.
If anyone has some ideas that would be great.
EDIT:
This error is thrown on the SQLite.Net-PCL library on this file line 380 but only on the device and not on the emulator.
For others to whom this may concern, I found the answer to my problem. The issue was with the Type not having any properties (the type in question the simple model class). Knowing that to be rubbish I found the following links that gave more information which I will relate in this post in case the links go dead:
Type.GetProperties returning nothing
NOTE: Be careful with assembly linker
If you're building with linker enabled you may need to use the class
somewhere, so it will not be ripped off at compile time. Sometimes,
only instantiating the class in your code is not enough, the linker
may detect that the instance is never used and will remove it anyway.
http://developer.xamarin.com/guides/ios/advanced_topics/linker/
The linking process can be customized via the linker behavior
drop-down in Project Options. To access this double-click on the iOS
project and browse to iOS Build > Linker Options, as illustrated below
(see link for details)
I have for now left it to be unlinked, however, I will try before release to get the linker to ignore these classes. Thanks for all your help.
I found my problem was just a (not that subtle) programming error. I was working with the TypeInfo class and wanted to use the Sqlite Connection method:
CreateTable (Type type);
What I had in my hand was a TypeInfo instance which I needed to convert back to the System.Type. I accidentally without thinking used the GetType() method instead of AsType() method which is obvious when you think about it. The clue I got was in the exception message along with the OP message was does System.Runtime have public properties?
var type = table.TypeInfo.AsType();
// var type = table.TypeInfo.GetType(); *WRONG*
connection.CreateTable(type);

Is it possible to use Gephi compiled with IKVM in a website?

I'm currently trying to load and use the Gephi Toolkit from within a .Net 4 C# website.
I have a version of the toolkit jar file compiled against the IKVM virtual machine, which works as expected from a command line application using the following code:
var controller = (ProjectController)Lookup.getDefault().lookup(typeof(ProjectController));
controller.closeCurrentProject();
controller.newProject();
var project = controller.getCurrentProject();
var workspace = controller.getCurrentWorkspace();
The three instances are correctly instantiated in a form similar to org.gephi.project.impl.ProjectControllerImpl#8ddb93.
If however I run the exact same code, with the exact same using statements & references, the very first line loading the ProjectController instance returns null.
I have tried a couple of solutions
Firstly, I have tried ignoring the Lookup.getDefault().lookup(type) call, instead trying to create my own instances:
var controller = new ProjectControllerImpl();
controller.closeCurrentProject();
controller.newProject();
var project = controller.getCurrentProject();
var workspace = controller.getCurrentWorkspace();
This fails at the line controller.newProject();, I think because internally (using reflector) the same Lookup.getDefault().lookup(type) is used in a constructor, returns null and then throws an exception.
Secondly, from here: Lookup in Jython (and Gephi) I have tried to set the %CLASSPATH% to the location of both the toolkit JAR and DLL files.
Is there a reason why the Lookup.getDefault().lookup(type) would not work in a web environment? I'm not a Java developer, so I am a bit out of my depth with the Java side of this.
I would have thought it possible to create all of the instances myself, but haven't been able to find a way to do so.
I also cannot find a way of seeing why the ProjectController load returned null. No exception is thrown, and unless I'm being very dumb, there doesn't appear to be a method to see the result of the attempted load.
Update - Answer
Based on the answer from Jeroen Frijters, I resolved the issue like this:
public class Global : System.Web.HttpApplication
{
public Global()
{
var assembly = Assembly.LoadFrom(Path.Combine(root, "gephi-toolkit.dll"));
var acl = new AssemblyClassLoader(assembly);
java.lang.Thread.currentThread().setContextClassLoader(new MySystemClassLoader(acl));
}
}
internal class MySystemClassLoader : ClassLoader
{
public MySystemClassLoader(ClassLoader parent)
: base(new AppDomainAssemblyClassLoader(typeof(MySystemClassLoader).Assembly))
{ }
}
The code ikvm.runtime.Startup.addBootClassPathAssemby() didn't seem to work for me, but from the provided link, I was able to find a solution that seems to work in all instances.
This is a Java class loader issue. In a command line app your main executable functions as the system class loader and knows how to load assembly dependencies, but in a web process there is no main executable so that system class loader doesn't know how to load anything useful.
One of the solutions is to call ikvm.runtime.Startup.addBootClassPathAssemby() to add the relevant assemblies to the boot class loader.
For more on IKVM class loading issues see http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader

Code Contract : ccrewrite exited with code -1?

I'm new to code contracts. I downloaded the latest build of code contract project (1.4.40314.1) and started to implement it in my project. When i enabled 'Runtume Checking' through Code Contracts Tab in VS2010, i got this Error
Error 1 The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite" "#Application1ccrewrite.rsp"" exited with code -1.
everytime i build the project. Plz help.
Now it's a major problem for me.
Every project using code contracts is showing same error in VS2010 Errors window and 'Application1ccrewrite.rsp' not found in output window, but it is there.
I tried out everything. I installed both versions (Pro, Std) but the problem persist. Plz help !
I had this problem as well. In my case the problem was that ccrewrite cannot work with files in a network folder but requires the project to be on your local hard disk.
I had this problem. The Assembly name and Default namespace of the class library that causes the problem had the same name as an existing DLL in the destination folder. I had been refactoring my code and whilst the namespaces in the CS files had all be changed to namespace2 the default namespace in the properties file was still namespace1
When I corrected this the files all built successfully...
Sometimes you can get this when your solution path is too long, especially with many projects.
Try moving to c:\temp and building it, it might fix it (although of course, this might not be a solution if you need it in the folder it currently is).
This bug I noticed in earlier CC versions and may now be fixed.
I don't know if you had the same problem as me, but I also saw this error. In my case, I had a method with a switch statement, and depending on the branch taken, different requirements applied:
static ITransaction CreateTransaction(
String transType,
MyType1 parm1,
/* Other params unimportant to this example */
String parm5)
{
switch (transType) {
case Transaction.Type.SOME_TRANSFER:
Contract.Requires<ArgumentNullException>(parm1.Account != null, "Account cannot be null.");
Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm5), "parm5 cannot be null or empty.");
// Create instance
return someInst;
case Transaction.Type.SOME_OTHER_TRANSFER:
Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm1.Type), "Type cannot be null or empty.");
Contract.Requires<ArgumentException>(!String.IsNullOrWhiteSpace(parm1.Number), "Number cannot be null or empty.");
// Create instance
return someInst;
/* Other cases */
default:
throw new ApplicationException("Invalid or unknown transaction type provided.");
}
}
This was giving me the error you noted in the Errors List when I tried to build. In the output window, I was getting this:
EXEC : Reference Assembly Generator
warning : Something is wrong with
contract number 1 in the method
'TerraCognita.LoanExpress.Domain.Loan.CreateLoanTransaction'
AsmMeta failed with uncaught
exception: Operation is not valid due
to the current state of the object.
I pushed each branch into a method of its own, making Contract.Requires the first lines of code in each method, and I no longer had a compilation problem. It appears that Contract.Requires must be the first lines of code in a method - which makes sense, since they are intended to be used to define pre-conditions.
Hope this helps.
The solution is to put the pre and pos conditions in the first lines. The ccrewrite does not accept that pre and post conditions are below command lines.

Categories