Visual Studio 2017 IWizard ProjectFinishedGenerating project is null - c#

I have the following code in my class that extends IWizard:
public void ProjectFinishedGenerating(Project project)
{
MessageBox.Show(project.Name);
}
But it gives me the error:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object.
Saying that project is null. Which is right according to my debugger. However, what on earth causes this? I would've thought the method only gets called with a non-null project. How can I fix this?

Related

Reflection. Why does my line return null in the code, but works fine in the debugger?

I have a line of code, an assignment, that assigns null when run, but when I visit in the debugger, the line does just what I want. The line is...
object instance = typeof(SqlEditorPackage).GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
In the below screenshot, you can see the local variable instance is null, whereas in the watch, the same line gives me a populated object. What is going on?
If this gives anyone ideas, here is the code for the Instance prop, from the SqlEditorPackage.dll, visited with ilspy
internal static SqlEditorPackage Instance
{
get
{
if (_instance == null)
{
_instance = (DemandLoadPackage("fef13793-c947-4fb1-b864-c9f0be9d9cf6") as SqlEditorPackage);
}
return _instance;
}
private set
{
_instance = value;
}
}
Enabling all exceptions, I see the following error, one of about 15 of the same type for various assemblies...
Managed Debugging Assistant 'LoadFromContext'
Message=Managed Debugging Assistant 'LoadFromContext' : 'The assembly named 'Microsoft.VisualStudio.Data.Tools.SqlEditor' was loaded from 'file:///C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/Extensions/Microsoft/SQLEditor/Microsoft.VisualStudio.Data.Tools.SqlEditor.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.'
I don't know if this is part of the problem, but I note that this refers to a 2019 version of SqlEditorPackage, not the 2015 version that I have referenced.

C# How to get the current Page Coded UI TEST in Wpf

I want to know if it's possible to get / know the current page in wpf.
In my project, I put this code and I have the correct page:
var current_page = (Window.Current.Content as Frame).Content.GetType();
Windows.Current.Content was null.
But in my UI Test project, I have the following error:
Result Message:
Test method CodedUITestProject1.CodedUiTest.CodedUITestMethod1 threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.

Instantiating a .NET class with a reference to a dll causes FileNotFoundException

I've added as reference PDFSharp classes for a project. When I tried to use a method in a class that includes PDFSharp libraries I get a FileNotFoundException that states I'm missing the referenced (PDFSharp) file (while I can assure you the dll file is there).
So I've tried adding and readding and changing the dll version, but still without success. So I switched to PDFClown, a similar purpose library, but the error is the same: FileNotFoundException at runtime.
The exception is thrown even before the method is executed.
Calling method (where the exception is thrown):
//method call: here the debugger stops at the breakpoint
ReportUtils.CreateFile(tempDirectoryPath ecc);
Called method:
using org.pdfclown.documents;
using org.pdfclown.documents.contents.composition;
using org.pdfclown.documents.contents.fonts;
using clownFiles = org.pdfclown.files;
class ReportUtils
{
public static void CreateFile(/*parameters*/)
{
//the debugger never enter here: the exception is thrown before
string filename = Settings.ReportFileName + String.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
//ecc
}
//...
Why is this exception showing up? Am I doing something wrong adding the references?
I could reproduce your issue by setting the option Copy Local on my library to false. Please, make sure this boolean is set to true..

What does "Method ...ClassInitialize has wrong signature ..." mean?

In my Visual Studio 2012 solution I have a C# project for unit testing C++/CLI code, e.g.
...
using System.IO;
using Stuff;
namespace MyCLIClassTest
{
[TestClass]
public class MyCLIClassTest
{
public MyCLIClassTest() {}
[ClassInitialize]
public static void Setup(TestContext testContext)
{
}
[TestMethod]
public void LibraryAccessTest()
{
...
}
}
}
Now, the C# tests all fail with a message like "Method MyCLIClassTest.MyCLIClassTest.ClassInitialize has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext."
After removing the ClassInitializer I got "Unable to set TestContext property for the class MyCLIClassTest.MyCLIClassTest. Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestContextImplementation' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..
I used DLLs of older unit testing framework versions. This happened because the project migrated recently to VS2012.
So, in the solution explorer under the test project you find "References". Right click it and select "Add reference..." to open the Reference Manager. Search for "unittest" and check the Microsoft.VisualStudio.QualityTools.UnitTestFramework with version number 10.1.0.0. Un-check all other versions of this assembly. Close the manager by clicking OK.
An alternate answer copied from a duplicate question: Why is a ClassInitialize decorated method making all my tests fail?
The [ClassInitialize] decorated method should be static and take exactly one parameter of type TestContext:
[ClassInitialize]
public static void SetupAuth(TestContext context)
{
var x = 0;
}
I had the exact same issue and removing/adding references as suggested by TobiMcNamobi did not solve it for me, however removing the reference, right click the project and selecting "Add > Unit test..." and thereby getting the reference re-generated worked. Not sure what the difference was compared to doing it manually.
Setup has wrong signature. Parameter 1 should be of type Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.
I was running a Load Test Project and had both v10.0.0.0 versions of the DLLs:
Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll
Microsoft.VisualStudio.QualityTools.WebTestFramework.dll
Changing the version LoadTestFramework to version 10.1 didn't fix it.
I had to goto my Unit Test Project and delete the MSTest.Adapter references:
Microsoft.VisualStudio.TestPlatform.TestFramework.dll
Microsoft.VisualStudio.TestPlatform.Extensions.dll
Then in the Unit Test Project add a reference to the v10.1
Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll

Publicize.exe exits with error "Value cannot be null. Parameter name : interfaceType

I'm trying to make private accessor class using Visual Studio 2010.
Here is the return of Publicize.exe:
Error occurred during processing of assembly xxx Value cannot be null.
Parameter name: interfaceType
I use internals and InternalVisibleTo in my project. Perhaps that is the cause of the problem?
Maybe you have an event in an internal interface within your module?
There's a bug about it:
http://connect.microsoft.com/VisualStudio/feedback/details/481332/creating-a-private-accessor-when-you-have-a-top-level-friend-interface-exposing-an-event-fails-in-publicize

Categories