Deleted class still works - VS 2012 - c#

I wanted to implement a simple activation function to my C# application. It was something like this:
class Activation
{
public Activation()
{
Some code...
}
public void SomeFunction()
{
Some code...
string s = NumberOfDaysToExpire();
}
}
The complete code is not a problem. The class sets some values to the Windows registry. I decided to launch the instance of this class in the main form's constructor and it worked fine.
The problem appeared when I decided to exclude this class from the project. The code shouldn't work but it still works !!! There is no declaration of this class in the whole project - so why does it still work ? I think this is a Visual Studio 2012 problem. Please help me.
Regards,
Mariusz

Related

How to open a browser and keep it open between coded UI tests in Visual Studio 2017 using C#

I am trying to make some coded UI tests to help automate some of the manual testing at the company I work at. I am pretty new to the CUIT part of visual studio, but I feel like I am figuring it out. However I am having an issue with the testing thread being closed before the other tests run.
So I want to make this testing fully automated, as in, all the developer will need to do is to click "Run all" and they will all run automatically. The problem that I am having is that the very first test needs to launch Internet Explorer, go to a website, and log into the website. The rest of the tests are based off of being logged into the system. However, after the first test, the browser closes and gets killed along with the first test method.
Any advice on this would be great, I have searched online for some answers but a lot are for very old versions of visual studio, and the ones I have tried don't work.
Thank you.
Edit: So inside each class lets say "CodedUITest1.cs", I can use the same browser in each of the [Test Method]s that I have in that class (as someone suggested below). The issue I have is that if I want a different test class to test different functionality, "CodedUITest2.cs", the browser will close when the first class finishes its tests.
If I'm understanding your question correctly, then This code segment should work for you:
BrowserWindow window;
[TestMethod]
public void Method1()
{
window = BrowserWindow.Launch(new Uri("http://www.bing.com"));
window.CloseOnPlaybackCleanup = false;
}
[TestMethod]
public void Method2()
{
window = BrowserWindow.Locate("Bing");
window.CloseOnPlaybackCleanup = false;
}
[TestMethod]
public void Method3()
{
window = BrowserWindow.Locate("Bing");
}
After reading the new info of this question, I have tested the code a bit. If you want to keep the browser open between CodeUITes1.cs and CodedUITest2.cs, then the following code segment may help you. It is adopted from the following link: https://blogs.msdn.microsoft.com/devops/2012/11/08/coded-ui-test-why-does-application-close-after-each-test-in-visual-studio-2012/
File: CodedUITest1.cs
public class CodedUITest1
{
static BrowserWindow browserWindowInstance = null;
public void LoadLocalHost()
{
if (browserWindowInstance == null)
{
browserWindowInstance = BrowserWindow.Launch(new System.Uri("YourWebSiteAddress"));
browserWindowInstance.CloseOnPlaybackCleanup = false;
browserWindowInstance.Maximized = !browserWindowInstance.Maximized;
}
else
{
browserWindowInstance.Maximized = !browserWindowInstance.Maximized;
}
}
[TestMethod]
public void CodedUITestMethod1()
{
LoadLocalHost();
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
this.UIMap.ClickNewsAndEvents();
}
CodedUITest2.cs file:
[TestMethod]
public void CodedUITestMethod2()
{
CodedUITest1 obj1 = new CodedUITest1();
obj1.LoadLocalHost();
// To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
this.UIMap.ClickNewsPage();
}
You can add more CodedUITest classes. Just create a new object like obj1 in the code sample of CodedUITest2 class, and use LoadLocalHost() method that resides in CodedUITest1.class from any subsequent classes. Hoping this will resolve your problem.

WPF Cefsharp instance/object reference in class not working

I am spending too much time trying to solve this issue: i am trying to create a Core, because the project is already confusing me and it is not that big. The Core is a Class outside the main Thread. On the main Thread i named the Browser, browser :
<cefSharp:ChromiumWebBrowser x:Name="browser" x:FieldModifier="public" />
In the class i call it like this:
public class Core : MainWindow
{
public void winstenVerlies()
{
var currentdirectory = "https://www.google.nl";
this.browser.Address = currentdirectory;
}
}
I have tried numerous ways, this is the way i like it but they all give me the same message:
"object reference is not set on an instance of an object."
Any help is appreciated.
Problem solved. i researched it for weeks now, from what i can see is the problem is the root, when i use this or the object/function name when calling it, it does not get passed the root of the class, instead of the root of the project. here is how you bypass it.
pass the object trough the class.
public void winstenVerlies(ChromiumWebBrowser b)
{
var currentdirectory = "https://www.google.nl";
b.Address = currentdirectory;
}
then call it like so.
Core Menu = new Core();
Menu.winstenVerlies(browser);
Now i try'd this befor, it gave me error messages the last time, i did not trace the source of the problems.
All i know is it working now, and i am happy.
Have a nice day.

System.TypeLoadException: Method 'get_xxx' does not have an implementation

There are a lot of questions floating around with this problem and i've worked through them ll with no joy.
I am receiving this error:
Method 'get_UserImageCDNUrl' in type 'App.Web.WebConfig' from assembly
'App.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does
not have an implementation.
Which is really strange because I am trying to run Api.Web which has no reference to App.Web, the only thing they have in common are references to other projects (Models.Domain and Models.DTO).
I have an interface:
IResourceCompiler in an assembly "Models.Domain"
I have an abstract class which implements this interface in the same assembly (Models.Domain) called WebConfigBase
In the "App.Web" and "Api.Web" projects they each have a class called WebConfig which inherit from WebConfigBase, therefore both WebConfig classes in App and Api are implementations of IResourceCompiler.
I tried to add a property
string UserImageCDNUrl {get;}
to IResourceCompiler and added the property to WebConfigBase
public string UserImageCDNUrl
{
get { return ""; }
}
so the property would be accessible to both Api and Web projects through their own WebConfig classes, and i get the exception above.
I have looked for hours to try and see why this happens with no joy.
I've cleared my Obj folders, cleaned, rebuilt, checked for any instances in GAC (there aren't any) and i'm still stuck on this.
Everything works fine until i try to add a new property to the interface (and base class)
OK, so bizarrely adding a reference to App.Web in Api.Web and removing it again has solved the issue.
I have no idea why, but it did.
I changed the version of App.Web to 1.0.0.1 and the error was still showing 1.0.0.0, which is what prompted me to do it.
I wish there was a more reasonable explanation but there isn't. Such an infuriating issue i'm just glad to be done with it.
Best of luck to anyone else who experiences this, my thought's are with you
For the records, in my case this was caused by two projects referencing different versions of the same package. At least fixing this solved the issue.
There can be many reasons for this, all the previous answers represent a case of this problem.
What I suggest doing is:
while your program is running open Resource Monitor -> CPU tab and in the search handles input box, search for the assembly that supposedly doesn't implement that method.
In the search results you'll see the path of your assembly, and most likely the path that you see isn't the one that you expect. Delete the assembly from this unexpected path so that the correct assembly gets loaded.
In many cases I become this error.
It seems like Cached assembly and I found them in UserProfile.
My solution is:
Save solution and close Visual Studio
Delete entire folder "c:\Users(user)\AppData\Local\Microsoft\VisualStudio\14.0\ProjectAssemblies\"
Start Visual Studio
Work...
Hope it helps.
I just remove the reference of current project (which is showing error) , and add again to other project in which project this was referenced build and it start working fine.
hope this help someone.
try this
public interface IResourceCompiler
{
string UserImageCDNUrl {get;}
}
public abstract class WebConfigBase : IResourceCompiler
{
public abstract string UserImageCDNUrl {get;}
}
public class WebConfig : WebConfigBase
{
public override string UserImageCDNUrl { return "whatever you want";}
}
or that way too:
public interface IResourceCompiler
{
string UserImageCDNUrl {get;}
}
public abstract class WebConfigBase : IResourceCompiler
{
public virtual string UserImageCDNUrl {get { return string.empty;}}
}
public class WebConfig : WebConfigBase
{
public override string UserImageCDNUrl { return "whatever you want";} // or return base.UserImageCDNUrl ;
}
I was seeing this problem in Visual Studio 2017.
Upgrading to visual studio 2019 solved the problem for me.

EditorWindow.GetWindow doesn't work

This is my code:
public class CrazyWindow: EditorWindow
{
[MenuItem("Window/CrazyWindow")]
public static void Window()
{
EditorWindow.GetWindow(typeof(CrazyWindow));
Debug.Log("It should have appeared!");
}
string test = "";
public void OnGUI()
{
test = EditorGUILayout.TextField ("Text Field", test );
}
}
I'm using Unity3D v. 4.3.4f1 (free version) on Windows 7.
I have no idea why this is happening, as I can see in tutorials in the internet, that's how it should be done. The script is also in the Editor folder.
I'm able to click on the option "CrazyWindow" in the window menu, and I also get the Debug message informing me that the window should be working, but nothing happens besides that. No window is created at all!
What might be the cause of my problem?
Problem solved.
As Bart mentioned, I was using a custom Editor Layout, which was the case for the window not showing.
I just switched to one of the factory editor layouts and: ta dah, the window was there...
Pretty buggy thought.
Try renaming the 'CrazyWindow' part in the MenuItem and of the class itself. Unity remembers whether a window is visible or not and somehow something goes wrong there. Probably it thinks your window is visible (in cache) while actually it is not.
As Bart said, it remembers useless things
Just make it remember what we want it to
private void OnLostFocus() {
GetWindow<CrazyWindow>().Close();
}

SpicIE Hostinstance null

I've been working on an IE9 plugin using the .net4 version of SpicIE. On my development machine, everything works great. While testing on a deployment machine, I keep getting a NullReferenceException when attempting HostInstance.BrowserRef.Navigate(URL). I added some logging and it is being reported as null on both machines, but it works without issue on the dev machine. I know at one time it worked on the deployment one and have no idea what might have broken it.
Relevant code follows:
From the plugin base:
public class KB_Toolbar : SpicIE.Host
{
...
public static KB_Toolbar HostInstance;
public KB_Toolbar() : base()
{
HostInstance = this;
}
public static void OpenURL(string URL)
{
if (HostInstance != null)
HostInstance.BrowserRef.Navigate(URL);
}
}
From the toolbar class:
private void MenuClick(object sender, EventArgs e)
{
var URL = vURL[(int)((ToolStripDropDownItem)sender).Tag];
KB_Toolbar.OpenURL(URL);
}
If I leave the HostInstance != null check there, it does not execute the next line on either machine. If I remove it, it executes with no problem on the dev, and throws a NRE on the deployment. I've tried a number of cheap hacks to work around it with no luck. I can't for the life of me figure out what is going on here, especially that it DOES work on the dev machine WHILE supposedly being null.
Any assistance would be greatly appreciated!
Solved it. The answer was a missing /codebase switch in the regasm command.

Categories