SystemNavigationManagerPreview does not exist in current Context - c#

So I wanted to try to disable the "X" (Close) Button in my UWP app. For testing I created a new UWP app. I then went to my Visual Studio projects:
\Visual Studio 2015\Projects\closerequesthandled\closerequesthandled
and opened Packageand edited following things:
First I added xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" and rescap
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
Then I added <rescap:Capability Name="confirmAppClose"/>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="confirmAppClose"/>
</Capabilities>
I get this warning:
But I read that this warning does nothing besides warning you so it still should work out.
Then I added this as a test to the MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += this.OnCloseRequest;
}
private void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e)
{
var x = 0;
}
}
But SystemNavigationManagerPreview and SystemNavigationCloseRequestedPreviewEventArgs gets a red underline:
The name `SystemNavigationManagerPreview` does not exist in the current context
and
The type or nmespace name `SystemNavigationCloseRequestedPreviewEventArgs` could not be found (are you missing a using directive or an assembly reference?)
How can I make this work?

This seems to be the same question on MSDN. From your folder we noticed that you are using Visual Studio 2015, and Visual Studio 2015 only support to 14393 SDK. As Stefan and my MSDN post mentioned, you have to set your min target version to 15063 first, then you can use the Windows.UI.Core.Preview API. So Visual Studio 2017 is required here for this specific feature.

Related

Cannot launch wix managed boostrapper with .net6

I’m trying to upgrade my project from wix v3 to wix v4.
The wix project are as follow :
A wix setup
A wix bundle
A wpf .net 6 class library managed
bootstaper
I followed this example https://github.com/wixtoolset/Bal.wixext/tree/master/src/test/examples/WPFCoreMBA and this doc https://wixtoolset.org/docs/development/wips/modify-burn-api/
When I publish the boostraper project, build the bundle and launched it I get this log and errors. How can I fix that ?
[0DA8:0DB4][2023-01-02T18:23:27]e000: Error 0x80131522: Failed to create delegate
through GetFunctionPointer.
[0DA8:0DB4][2023-01-02T18:23:27]e000: Error 0x80131522: Failed to create the .NET Core
bootstrapper application factory.
[0DA8:0DB4][2023-01-02T18:23:27]e000: Error 0x80131522: Failed to create BA.
[0DA8:0DB4][2023-01-02T18:23:27]e000: Error 0x80131522: Failed to load BA.
[0DA8:0DB4][2023-01-02T18:23:27]e000: Error 0x80131522: Failed while running
The bundle.wxs
<BootstrapperApplication>
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\LanguageSelector.dll" Name="LanguageSelector.dll" bal:BAFactoryAssembly="yes" />
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\LanguageSelector.deps.json" Name="LanguageSelector.deps.json"/>
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\LanguageSelector.runtimeconfig.json" Name="LanguageSelector.runtimeconfig.json" />
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\WixToolset.Mba.Core.dll" Name="WixToolset.Mba.Core.dll" />
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\mbanative.dll" Name="mbanative.dll" />
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\GalaSoft.MvvmLight.dll" Name="GalaSoft.MvvmLight.dll" />
<bal:WixDotNetCoreBootstrapperApplicationHost />
The LanguageSelectorFactory0cs
[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(LanguageSelector.LanguageSelectorFactory))]
namespace LanguageSelector
{
using WixToolset.Mba.Core;
public class LanguageSelectorFactory : BaseBootstrapperApplicationFactory
{
private static int loadCount = 0;
protected override IBootstrapperApplication Create(IEngine engine,
IBootstrapperCommand bootstrapperCommand)
{
if (loadCount > 0)
{
engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)");
}
++loadCount;
return new LanguageSelector(engine, bootstrapperCommand);
}
}
}
In your project file (.csproj) for bootstrapper application (your custom UI application known as BA) you have to add a reference to WixToolset.Dnc.HostGenerator package using Package manager console:
Install-Package WixToolset.Dnc.HostGenerator -Version 4.0.0-rc.1
Alternatively, make sure you have the required references in the mentioned BA project file:
<ItemGroup>
<PackageReference Include="WixToolset.Mba.Core" Version="4.0.0-rc.1" />
<PackageReference Include="WixToolset.Dnc.HostGenerator" Version="4.0.0-rc.1" />
</ItemGroup>
The managed BA assembly targeting .NET 6 or later requires WixToolset.Dnc.HostGenerator. Dnc is the abbreviation for Dot Net Core.
Once you have all this set, build and published you have to ensure the entire project output goes to Wix Payload. Including WixToolset.Mba.Core.dll and mbanative.dll. So, your Bundle.wxs have to include these DLLs. In your case should be something like:
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\mbanative.dll" />
<Payload SourceFile="..\LanguageSelector\bin\Release\net6.0-windows\publish\win-x86\WixToolset.Mba.Core.dll" />
It could be a lot of DLLs in the project output. So, I personally use the HarvestDirectory functionality in .wixproj to harvest project output directory as a PayloadGroup section. Let me know if you need more details on this.

.Net 6.0 Windows App Cant Reference System

So the weirdness has hit. I created a new Visual Studio 2022 - fully patched, updated, and current.net 6.0 Windows Desktop app. It has 1 form that has a menu bar dragged from the toolbox on it and that is it. I have done nothing else to it! System, Form, void, object, EventArgs, and Application are all red and not available (see below)
using System;
namespace Developmeny_Test_Application
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
}
private void e7xitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
This is as basic as it gets and can I get Visual Studio to let it in?
Under Dependencies/COM it is showing an orange triangle (which I always thought meant depreciated but as this was created with the wizard templates that's not likely)
So my question is what am I missing? All the web searching I have done has revealed nothing of any use.
Any help is gratefully appreciated.
Added as an edit for more information
The section that has the triangle has this section in the project file :
<ItemGroup>
<COMReference Include="{bee4bfec-6683-3e67-9167-3c0cbc68f40a}">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>4</VersionMinor>
<VersionMajor>2</VersionMajor>
<Guid>bee4bfec-6683-3e67-9167-3c0cbc68f40a</Guid>
</COMReference>
</ItemGroup>
That COM-Reference is fishy. You should not need that. When I do the same (create a new Winforms project and add a "MenuStrip" to the form) I'm not getting that reference.
I'm assuming you accidentally added a component from a third-party library to your form, which caused this strange reference. Just delete that section from the project file and see what happens. If the error persists, please quote the exact error message you get.

UWP: Cannot load PWM Controllers using Lightning on Raspberry Pi 2?

i justed started working on an older Project i started once, but unfortunately the PWM Controller is not working anymore with the Lightning Driver. I am using Visual Studio 2017, the RPi2 is running at 10.0.15063.414 and I've installed the following Nuget-Packages:
Microsoft.IoT.Lightning (v1.1.0)
Microsoft.NETCore.UniversalWindowsPlatform (v5.3.3)
WinRTXamlToolkit.Controls.DataVisualization (v2.3.0)
The Project includes references to
Analyzer
Microsoft.IoT.Lightning
Microsoft.NETCore.UniversalWindowsPlatform
%ClassesLibrary%
UniversalWindows
Windows IoT Extensions for the UWP
WinRTXamlToolkit.Controls.DataVisualization,
where %ClassesLibrary% is an user-defined Project containing some classes for my Project. In the configuration web Interface of Windows IoT Core in the devices section, the Direct Memory Mapped Driver (Current Driver) is selected.
My initialization Code Looks like this
private static async Task InitOnboardHardware()
{
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
GpioController gpioController = GpioController.GetDefault();
var pwmControllers = await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider());
if (pwmControllers != null)
{
m_PWMController = pwmControllers[1];
//m_PWMController = (await PwmController.GetControllersAsync(LightningPwmProvider.GetPwmProvider()))[1];
m_PWMController.SetDesiredFrequency(100);
m_RPin = m_PWMController.OpenPin(18);
m_GPin = m_PWMController.OpenPin(23);
m_BPin = m_PWMController.OpenPin(24);
m_WPin = m_PWMController.OpenPin(25);
m_RPin.SetActiveDutyCyclePercentage(0);
m_GPin.SetActiveDutyCyclePercentage(0);
m_BPin.SetActiveDutyCyclePercentage(0);
m_WPin.SetActiveDutyCyclePercentage(0);
m_RPin.Start();
m_GPin.Start();
m_BPin.Start();
m_WPin.Start();
m_IsHardwareInitialized = true;
}
}
}
The PwmController.GetControllersAsync-method never completes and my application gets stuck on starting up. Also the commented Shorter Version is not working anymore?!
I have really no clue what i could be missing. Therefore, i would greatly appreciate any help.
Thank you in advance!
EDIT: I also tried another sample (https://github.com/lprichar/WindowsIotPwmExample), where i replaced the embedded C/C++ lightning library by the NuGet Package (same Version as in my Project). The sample also Fails: the Pins are all null, because PwmController.GetControllersAsync never completes :-(
EDIT2: I forgot to mention that my package.appxmanifest file also includes the following changes
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp iot">
as well as
<Capabilities>
<Capability Name="internetClient" />
<iot:Capability Name="lowLevelDevices" />
<DeviceCapability Name="109b86ad-f53d-4b76-aa5f-821e2ddf2141" />
</Capabilities>
Please also see my comment to the first post. I had to Change this line
GpioController gpioController = GpioController.GetDefault();
to an async method call
GpioController gpioController = await GpioController.GetDefaultAsync();
and now everythings runs fine!

Treat all warnings as errors

This should be obvious to do, but I just couldn't make it work...
What I'm trying to do is simple: I would like my compilation to fail with an error if there is a warning. Yes, the famous TreatWarningsAsErrors...
I configured it in my C# project properties
This results in the expected TreatWarningsAsErrors section in my csproj:
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
So far so good, if I add an useless private variable in my code, it results in a compilation error:
private int unused;
Error 3 Warning as Error: The field 'XXXX.unused' is never used
But the whole problem is, I can't make it work for assembly reference issues. If I have a reference to an unknown assembly, the compiler (either devenv or msbuild) throws a warning, but I want an error instead.
Ultimately, I'm trying to configure a gated check-in TFS build configuration, so TFS would reject a commit in case there is a "The referenced component 'XXXX' could not be found." warning. Something simpler than modifying the build process template would be great.
MSBuild warnings (all start with MSB*) as opposed to CSC warnings cannot be suppressed nor promoted to errors. For the reason the ResolveAssemblyReference task prints its messages on the fly and does not aggregate any of them.
The only feasible solution is reading the MSBuild log files created during the TFS build.
I think the most elegant solution is to implement a custom Build CodeActivity. The following is a simple activity that will output to results any files containing a given SearchString:
using System;
using System.Activities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.TeamFoundation.Build.Client;
namespace MyBuildActivities.FileSystem
{
[BuildActivity(HostEnvironmentOption.Agent)]
public sealed class ReadStringFromFile : CodeActivity
{
[RequiredArgument]
public InArgument<IEnumerable<string>> Files { get; set; }
[RequiredArgument]
public InArgument<string> SearchString { get; set; }
public OutArgument<string> Result { get; set; }
protected override void Execute(CodeActivityContext context)
{
var files = context.GetValue(Files);
var searchString = context.GetValue(SearchString);
var list =
(files.Where(file => File.ReadAllText(file).Contains(searchString))
.Select(file => string.Format("{0} was found at {1}", searchString, file))).ToList();
if(list.Count > 0)
Result.Set(context, string.Join(Environment.NewLine, list));
}
}
}
Declared in the build process template like so:
xmlns:cfs="clr-namespace:MyBuildActivities.FileSystem;assembly=MyBuildActivities"
Invoked just at the end of the Compile and Test for Configuration sequence:
<Sequence DisplayName="Handle MSBuild Errors">
<Sequence.Variables>
<Variable x:TypeArguments="scg:IEnumerable(x:String)" Name="logFiles" />
<Variable x:TypeArguments="x:String" Name="readStringFromFileResult" />
</Sequence.Variables>
<mtbwa:FindMatchingFiles DisplayName="Find Log Files" MatchPattern="[String.Format("{0}\**\*.log", logFileDropLocation)]" Result="[logFiles]" mtbwt:BuildTrackingParticipant.Importance="Low" />
<cfs:ReadStringFromFile Files="[logFiles]" SearchString="MSB3245" Result="[readStringFromFileResult]" />
<mtbwa:WriteBuildMessage DisplayName="Write Result" Message="[readStringFromFileResult]" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" />
<If Condition="[readStringFromFileResult.Count > 0]" DisplayName="If SearchString Was Found" mtbwt:BuildTrackingParticipant.Importance="Low">
<If.Then>
<Throw DisplayName="Throw Exception" Exception="[New Exception(readStringFromFileResult)]" mtbwt:BuildTrackingParticipant.Importance="Low" />
</If.Then>
</If>
</Sequence>
I've tested this on TFS 2012 though it should work for TFS 2010 as well.
MSBuild 15 now supports a /warnaserror flag, which forces MSBuild warnings to be treated as errors.
MSBuild 15 is intalled with Visual Studio 2017 but can also be downloaded from GitHub
This GitHub issue explains why it cannot be set via an MSBuild property (tl;dr a property is too late)

VSIX extension for VS2012 not running when debugging

I created a new VSIX extension project in Visual Studio 2012, and wrote a MEF classifier (as a test) that should simply highlight all text in a .mylang file. Here are the relevant parts of my .NET 4.5 code:
internal static class MyLangLanguage
{
public const string ContentType = "mylang";
public const string FileExtension = ".mylang";
[Export(typeof(ClassificationTypeDefinition))]
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;
[Export]
[FileExtension(FileExtension)]
[ContentType(ContentType)]
internal static FileExtensionToContentTypeDefinition MyLangSyntaxFileExtensionDefinition = null;
}
[Export(typeof(IClassifierProvider))]
[ContentType(MyLangLanguage.ContentType)]
[Name("MyLangSyntaxProvider")]
internal sealed class MyLangSyntaxProvider : IClassifierProvider
{
[Import]
internal IClassificationTypeRegistryService ClassificationRegistry = null;
public IClassifier GetClassifier(ITextBuffer buffer)
{
return buffer.Properties.GetOrCreateSingletonProperty(() => new MyLangSyntax(ClassificationRegistry, buffer));
}
}
internal sealed class MyLangSyntax : IClassifier { }
Here is the full code.
These are the relevant parts from my source.extension.vsixmanifest file. Based on suggestions and similar files I found across the web, I added the dependency on MPF and the two assets.
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<!-- ... -->
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="4.5" />
<Dependency d:Source="Installed" Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" Version="[11.0,12.0)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
</PackageManifest>
I also tried a version 1.0 manifest:
<?xml version="1.0" encoding="utf-8"?>
<Vsix Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
<!-- ... -->
<References />
<Content>
<MefComponent>|%CurrentProject%|</MefComponent>
</Content>
</Vsix>
When I run it, it starts an experimental instance of Visual Studio 2012, and the Extensions and Updates window shows that my extension is active. However, it does not do anything when I load or create a .mylang file. Any exceptions I throw (as a test) from my extension are never thrown. Breakpoints are never hit, and get an exclamation mark with the following warning:
The breakpoint will not currently be hit. No symbols have been loaded for this document.
It feels as if my extension is never really loaded at all. My problem is similar to this problem and this problem, but I'm using Visual Studio 2012 which uses a new VSIX manifest format.
What I know:
I can find my DLL and VSIX file in the %localappdata%\Microsoft\VisualStudio\11.0Exp\Extensions\MyLang\VSIXProject1\1.0 folder, so I know they are copied.
Their timestamp corresponds to when I last built the project, so I know they are up-to-date.
Project Properties > Debug > Start external program: is already automatically set to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe, and the Command line arguments were automatically set to /rootsuffix Exp.
The Visual Studio log (created with the /log option) has two entries related to my extension: Successfully loaded extension... and Extension is enabled....
My DLL does not appear on the Modules tab (list of all loaded DLLs) of the debugging Visual Studio, while some (not all) other extensions do appear.
It doesn't get loaded in Visual Studio 2012 or 2010 both on my laptop and my desktop PC.
What I've tried:
Set <IncludeAssemblyInVSIXContainer> to true in the .csproj file, per this suggestion, but it did not make any difference.
I can't add the line <MefComponent>|%CurrentProject%|</MefComponent> to the source.extension.vsixmanifest file as it uses a different format (2.0) than VSIX projects for previous versions of Visual Studio (1.0).
This suggestion (setting IncludeAssemblyInVSIXContainer and friends in my .csproj to true) but it does not make a difference. And my breakpoints are still showing the warning and not being hit.
Reset the VS Experimental instance using the Reset the Visual Studio 2012 Experimental Instance shortcut in the Start Menu, as per this suggestion. It didn't make a difference.
How can I at the very least be sure my VSIX MEF extension is loaded and works? And if possible, how can I make by breakpoint work and debug it?
Edit: The problem is you've improperly exported your ContentTypeDefinition as a ClassificationTypeDefinition. You should use the following instead:
[Export] // <-- don't specify the type here
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;
Here's my two guesses right now:
Try removing the following line from your vsixmanifest. I assume you do not have a class in your project that extends Package, in which case Visual Studio might be refusing to load your package due to the following Asset line (your extension does not actually provide this asset).
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
If that fails, try replacing your current source.extension.vsixmanifest with one written to the old schema (version 1.0). I know this form still works in Visual Studio 2012 because all ~20 extensions I work on (with >10 public releases) use the old schema.
280Z28 solved the problem! For completeness, this is the full tried and tested code that will create a super simple VSIX Visual Studio MEF extension that colors all text in a .mylang file blue (or whatever the current keyword color is).
How to create a simple coloring MEF VSIX extension
Make sure you have the Visual Studio SDK installed. (VS2010 SP1 SDK, VS2012 SDK)
Create a new VSIX Project(From the template under Installed → Templates → Visual C# → Extensibility.)
Enter something in the Author field of the VSIX manifest editor, then save and close it.
Add references to the following libraries,version 10.0.0.0 for VS2010, or 11.0.0.0 for VS2012:
Microsoft.VisualStudio.CoreUtility.dll
Microsoft.VisualStudio.Language.StandardClassification.dll
Microsoft.VisualStudio.Text.Data.dll
Microsoft.VisualStudio.Text.Logic.dll
Microsoft.VisualStudio.Text.UI.dll
Microsoft.VisualStudio.Text.UI.Wpf.dll
Add a reference to the following library:
System.ComponentModel.Composition.dll version 4.0.0.0
Create and add a new code file MyLang.cs, and copy-and-paste the code below in it.
Edit source.extension.vsixmanifest as XML.
For Visual Studio 2010, add the following XML just before the closing tag </Vsix>, and save:
<Content>
<MefComponent>|%CurrentProject%|</MefComponent>
</Content>
(If there is already an empty <Content/>, remove it.)
For Visual Stuio 2012, add the following XML just before the closing tag </PackageManifest>, and save:
<Assets>
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%|" />
</Assets>
(If there is already an empty <Assets/>, remove it.)
Only for Visual Studio 2010:
Unload the VSIX project (right-click the project → Unload project).
Edit the .csproj project file (right-click the project → Edit MyProject.csproj).
Change the value at <IncludeAssemblyInVSIXContainer> to true.
Save and close the file.
Reload the VSIX project (right-click the project → Reload project).
Now build and run it. When you load a .mylang file, all text should be colored blue (or whatever the default keyword color is).
MyLang.cs
using Microsoft.VisualStudio.Language.StandardClassification;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
namespace VSIXProject1
{
internal static class MyLangLanguage
{
public const string ContentType = "mylang";
public const string FileExtension = ".mylang";
[Export]
[Name(ContentType)]
[BaseDefinition("code")]
internal static ContentTypeDefinition MyLangSyntaxContentTypeDefinition = null;
[Export]
[FileExtension(FileExtension)]
[ContentType(ContentType)]
internal static FileExtensionToContentTypeDefinition MyLangSyntaxFileExtensionDefinition = null;
}
[Export(typeof(IClassifierProvider))]
[ContentType(MyLangLanguage.ContentType)]
[Name("MyLangSyntaxProvider")]
internal sealed class MyLangSyntaxProvider : IClassifierProvider
{
[Import]
internal IClassificationTypeRegistryService ClassificationRegistry = null;
public IClassifier GetClassifier(ITextBuffer buffer)
{
return buffer.Properties.GetOrCreateSingletonProperty(() => new MyLangSyntax(ClassificationRegistry, buffer));
}
}
internal sealed class MyLangSyntax : IClassifier
{
private ITextBuffer buffer;
private IClassificationType identifierType;
private IClassificationType keywordType;
public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
internal MyLangSyntax(IClassificationTypeRegistryService registry, ITextBuffer buffer)
{
this.identifierType = registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier);
this.keywordType = registry.GetClassificationType(PredefinedClassificationTypeNames.Keyword);
this.buffer = buffer;
this.buffer.Changed += OnBufferChanged;
}
public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan snapshotSpan)
{
var classifications = new List<ClassificationSpan>();
string text = snapshotSpan.GetText();
var span = new SnapshotSpan(snapshotSpan.Snapshot, snapshotSpan.Start.Position, text.Length);
classifications.Add(new ClassificationSpan(span, keywordType));
return classifications;
}
private void OnBufferChanged(object sender, TextContentChangedEventArgs e)
{
foreach (var change in e.Changes)
ClassificationChanged(this, new ClassificationChangedEventArgs(new SnapshotSpan(e.After, change.NewSpan)));
}
}
}
Set <IncludeAssemblyInVSIXContainer> to true in the .csproj file, per
this suggestion.
I had exactly the same problem and this solved it. Do a full rebuild.

Categories