Error trying to use WordsSegmenter.GetTokens() - c#

The code:
WordsSegmenter s = new WordsSegmenter("en-US");
var words = s.GetTokens("The price of this API is €10,000.99.");
gives me a build error: "Error 2 The type 'System.Collections.Generic.IReadOnlyList`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I have System.Collections.Generic referenced and suspect that the error above is disguising the real problem.
I'm building this in Visual Studio Express for Windows Desktop. Do I perhaps have to use VS Express for Windows?
Changing the target Framework of my project to other 4.x versions doesn't help.

Two actions fixed this: Opening my project.csproj file in a text editor and changing the TargetPlatformVersion node to "8.1". Then added references to Windows.winmd and Windows.Runtime.WindowsRuntime.dll.
Kudos to Xavier H at Intel for this post: https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications

Related

Fixing "They type 'X' exists in both 'Y' and 'Z'" C# error for System.ServiceModel in LINQPad

If I:
Create a new C# query in LINQPad 6.
Add the System.ServiceModel.Http NuGet package or another package that references it.
Try to instantiate a class from the System.ServiceModel namespace, for example System.ServiceModel.BasicHttpBinding.
Leading to the following .linq file:
<Query Kind="Expression">
<NuGetReference>System.ServiceModel.Http</NuGetReference>
</Query>
new System.ServiceModel.BasicHttpBinding()
Then I get a compile error:
CS0433 The type 'BasicHttpBinding' exists in both 'System.Private.ServiceModel, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.ServiceModel.Http, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
If I create a project in Visual Studio and add the same NuGet package and code, I do not get this error.
According to the C# Language reference for the error, it should be possible to resolve by using the -reference compiler option or by not referencing one of the assemblies. However, I can't seem to find a way to use this compiler option in LINQPad, nor can I find any way to remove the assembly reference to System.Private.ServiceModel.
How can I fix the error?
This is a bug in LINQPad, triggered by an obscure scenario. The System.Private.ServiceModel package contains a lib folder with an assembly which is required at runtime, and a ref folder with a underscore.underscore file which indicates that no assemblies should be referenced by the compiler. Because LINQPad finds no reference assemblies, it feeds the compiler the assembly in the lib folder, which causes the error.
I've got a fix ready and regression tests are currently running. The fix will likely make it into the 6.11.2 beta build, which should be released in a day or two.

Error when using RazorTemplates library: 'CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced'

On some machines, executing a razor template via RazorTemplates works OK.
On others, I receive the following message:
TemplateCompilationException
error CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Info:
This is within a WPF application running on .NET 4.7.
The assembly has a reference to System.Runtime.4.3.0\lib\net462\System.Runtime.dll (v4.1.1.0)
However at runtime, this assembly does not show up in the 'Modules' list.
It seems the Attribute object exists in both System.Runtime and mscorlib.
Looks like this is an underlying issue somewhere between win10 and the RazorTemplates library.
In the end i switched from RazorTemplates to RazorEngine: https://github.com/Antaris/RazorEngine
And there is a page here that explains how to fix the problem via a Resolver:
https://github.com/Antaris/RazorEngine/issues/416
System.Runtime is part of the .Net Framework and is installed in the GAC during framework installation.
This could happen for two possible reasons:
It's not on the machine.
It's the wrong version.
For the machines this fails on check what version of the .Net runtime they have and/or inspect the GAC for this file and version.
Missing the framework, install it. :-)
If machines have a version but it's not the expected version do either:
Install the correct framework version
Use a binding redirect in your config file

CS1705 error while adding a C++ project to solution

Hi and thanks in advance.
I'm using TFS build 2013 (team services, not on premise) to build my solution. After creating a new C++ project in the solution I'm unable to build successfully.
The error I'm getting on the build machine is:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): An error has occurred during compilation. error CS1705: Assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'Microsoft.Build.Framework,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher
version than referenced assembly 'Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
(219): The "SetEnvironmentVariable" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name
of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask
interface. 3.) The task is correctly declared with <UsingTask> in the project file, or
in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin\amd64" directory.
I've red about error CS1705 on the internet but I still don't understand why I get this error - the project is an empty project which has no references what so ever and no other project reference it either.
I'm targeting .NET framework 4.6.1 on all my C# projects and in my build definition I'm adding these msbuild arguments: /tv:14.0 /p:VisualStudioVersion=14.0 hence it uses the 2015's version of the c# compiler.
The target platform for this C++ project is VS 2015 (v140) as follows:
C++ project configuration
Needless to say that when I'm removing this project from the list of project to build (configuration manager) - the solution builds successfully.
Any help/clue would be greatly appreciated!
The problem was something other than what I thought it was. Seems it's got something to do with CodeAnalysis and some environment variable related to it.
In my build definition I'm disabling CodeAnalysis and even inside the C++ project properties It's explicitly disabled. After I commented out some attributes on the "SetCABuildNativeEnvironmentVariables" target inside this file on the build machine:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets"
The problem disappered.
This is a nasty workaround however since I'm not fully aware of what's really happening.
Thanks a lot anyways!
Seems there are something still point to "Microsoft.Build.Framework, Version=12.0.0.0"
The /tv:14.0 command argument doesn't work as expected. See:
BuildActivity ignores ToolsVersion
As a workaround, you need to customize the build process template:
Open the template in Visual Studio and find the Run MSBuild for
Project MSBuild activity.
Set ToolVersion to "14.0".
Set ToolPath to target to MSBuild14 (by default: "C:\Program Files
(x86)\MSBuild\14.0\Bin").
Check in this build process template and re-queue the build.
You can also refer the answer from Marson in TFS 2013 building .NET 4.6 / C# 6.0

Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies

I have this exception generated on some user machines (~1 of 20):
Could not load file or assembly 'System, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
dependencies. The system cannot find the file specified.
I found several references to this error over the web and this site but nothing helped.
I have an add-in application which uses WCF to connect to the server. The add-in built with .NET Framework 3.5 with VS 2008.
The error is reproducible on one of the test machines in only one user account. I install my application and can only reproduce this from one account on this machine everywhere else it is working fine. Furthermore it is only reproducible with only one version of host application which I created add-in for (I assume because it uses differnet .NET Frameworks).
I have checked the fuse logs and I see the following:
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files\SolidWorks Corp\SolidWorks\sldworks.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Home\User
LOG: DisplayName = System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/SolidWorks Corp/SolidWorks/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
So by some reasons it is trying to use v2.0.50727\mscorwks.dll loader to load the Version=4.0.0.0 of System.dll. On build machine I'm referring 2.0.0.0 version of System.dll.
I had this same problem - some users could pull from git and everything ran fine. Some would pull and get a very similar exception:
Could not load file or assembly '..., Version=..., Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.
In my particular case it was AjaxMin, so the actual error looked like this but the details don't matter:
Could not load file or assembly 'AjaxMin, Version=4.95.4924.12383, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.
It turned out to be a result of the following actions on a Solution:
NuGet Package Restore was turned on for the Solution.
A Project was added, and a Nuget package was installed into it (AjaxMin in this case).
The Project was moved to different folder in the Solution.
The Nuget package was updated to a newer version.
And slowly but surely this bug started showing up for some users.
The reason was the Solution-level packages/respositories.config kept the old Project reference, and now had a new, second entry for the moved Project. In other words it had this before the reorg:
<repository path="..\Old\packages.config" />
And this after the reorg:
<repository path="..\Old\packages.config" />
<repository path="..\New\packages.config" />
So the first line now refers to a Project that, while on disk, is no longer part of my Solution.
With Nuget Package Restore on, both packages.config files were being read, which each pointed to their own list of Nuget packages and package versions. Until a Nuget package was updated to a newer version however, there weren't any conflicts.
Once a Nuget package was updated, however, only active Projects had their repositories listings updated. NuGet Package Restore chose to download just one version of the library - the first one it encountered in repositories.config, which was the older one. The compiler and IDE proceeded as though it chose the newer one. The result was a run-time exception saying the DLL was missing.
The answer obviously is to delete any lines from this file that referenced Projects that aren't in your Solution.
I got this after downgrading a project from .net 4.5 to .net 3.5.
To resolve I had to go in to the project - properties - settings window and delete all my settings, save the project, exit and restart visual studio, go back into project - properties -settings window and re-enter all my settings and their default values
This worked for me.
Go to Project->Propertied->Target Frawork->Change frame work like 3.5 to 4.0
I had the problem under Linux and I needed to install those. I don't know which one actually fixed the problem, but that error was gone after that:
apt-get install mono-utils mono-runtime-sgen mono-runtime-common \
mono-runtime-boehm mono-runtime-dbg mono-xbuild
I've seen this a couple times, and it is usually fixed by running a repair on .NET Framework (whichever version the application is trying to use).
You are using .net 4? - Maybe on the clients there is only the ".net framework 4 client profile" installed. Try to install full package!!
Download here
In my case, I was able to find issue with ScriptManager by setting Debug=true in web.config file
I answered too late but it has worked in my case.If you are facing this issue in your project please add the following line in your web.config :
<compilation batch="false" >
This worked in my case. If you already have compilation tag in your web.config then add only batch="false" property to it.
You can enable NuGet packages and update you dlls. so that it work.
or you can update the package manually by going through the package manager in your vs if u know which version you require for your solution.
Even I have experience some more strange things, I can see there is no dll in GAC from where the dll is loading but windows > Module shows system.dll version=4.0.0.0 loaded
i just changed my target .net framework and it worked .in my case i changed from .net 4.7 to .net 4.
Right click your solution and select properties
selct properties
Click Application >> Target Framework
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
this is my problem. I installed system.configuration assembly in the project and other class libraries also. now the problem has gone.
am used net 6.0 with aspcore.report and problem like this happened with me
I installed system.configuration assembly in the server project problem solved

Does Scintilla need a directive? I keep getting an error?

So, when I drag in Scintilla to my C# form, and try to run it, I get the error:
The type or namespace name
'ScintillaNet' could not be found (are
you missing a using directive or an
assembly reference?)
The error appears to be coming from the designer for Form1.
I also get the warning (but not error):
The referenced assembly "ScintillaNet"
could not be resolved because it has a
dependency on "System.Design,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which
is not in the currently targeted
framework
".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies
not in the targeted framework or
consider retargeting your project.
So, I can't run my program...
What's wrong, and how do I fix it? I've installed scintilla just like how the directions for it suggested...
I was also experiencing this error (although I am hosting in WPF not WinForms). It was caused by Visual Studio 2010 defaulting the project to .Net 4.0 Client profile rather than the full .Net 4.0 profile.

Categories