I am using JSON.NET which has the LinqBridge .dll merged in. LinqBridge allows Linq to be accessed from .NET 2. If I try to use Linq, even after importing System.Linq, I receive the following error:
Error 13 Could not find an implementation of the query pattern for source type 'int[]'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? C:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\Program.cs 27 25 WindowsSoftToken
If I try to include LinqBridge, then because JSON.NET already includes it, I receive this warning. Additionally, I have included the same component twice, which is inefficient:
Warning 2 The predefined type 'System.Action' is defined in multiple assemblies in the global alias; using definition from 'c:\Users\chrisl\Desktop\SoftTokens\Windows Desktop Soft-Token\libs\Newtonsoft.Json.Net20.dll' WindowsSoftToken
If I browse Newtonsoft.Json.Net20 in the object browser, I see that System.Linq appears empty, even after I have slected Show hidden types and methods.
Is it possible to access Linq from the JSON.NET dll or to suppress the error messages?
The Enumerable static class that provides the LINQ query operators in the LINQBridge assembly is still exposed in the System.Linq namespace.
You still need to have the using directive for System.Linq as directed in your first error message.
Update:
It turns out the LINQBridge assembly that's merged into Newtonsoft.Json.Net20.dll has been "internalized" which I hadn't noticed at first. This means your code can't reference the Enumerable type that the compiler needs to "implement the query pattern." So you do have to reference the LINQBridge assembly yourself, but then you get the warning about duplicate definitions as you mentioned.
You can disable the duplicate class warning by going to the Build tab of your project properties and enter "1685" in the "Suppress warnings:" box.
But what would probably be better would be to build your own version of JSON.net from source without merging in LINQBridge.
Related
This is a question to gather possible causes of the compile error "Schema reference [assembly].[type] is not a valid reference or does not exist in the current project".
In a BizTalk solution, I have a common schemas assembly with a KiTH MsgHead schema that I have to reference as an import in another schema in another project. This is perfectly possible, even though search results on the web made me believe it might not.
An import statement like this is correct, without a doubt:
<xs:import namespace="http://www.kith.no/xmlstds/msghead/2006-05-24" schemaLocation="HP.BizTalk.KiTH.Schema.MsgHead_v12.MsgHead_v1_2"/>
Here the schema has type name MsgHead_v1_2 and exists in an assembly HP.BizTalk.KiTH.Schema.MsgHead_v12. When building the solution, I get the following compile error:
I will answer my own question with the solution that I couldn't find in any of the search results on the web.
When I created the common schemas project, I imported it from another repository and had to change project name, namespaces etc. Also the AssemblyInfo.cs file was recreated because of issues related to renaming.
If the assembly attribute BizTalkAssembly is missing, the compiler doesn't complain at all. But since it's no longer a BizTalk assembly, it leads to issues that can be very confusing and impossible to understand. I couldn't use the schema from the common assembly in a BizTalk Map, and I couldn't import it into another schema, as the question says. So by adding in the following line to AssemblyInfo.cs, the misleading compile error disappeared:
[assembly: Microsoft.XLANGs.BaseTypes.BizTalkAssembly(typeof(Microsoft.BizTalk.XLANGs.BTXEngine.BTXService))]
I am new to webforms. I am trying to setup a linq to sql connection. I did it the (what I think is) the standard way. I added a linq to sql class. Then I went to my database explorer and dragged a table in and saved. Whenever I try to load the project in the browser I am getting the following error:
The type or namespace name 'Linq' does not exist in the namespace 'System.Data'
I am kind of at a loss here. I googled around. I saw some of the standard solutions like add a reference to System.Data.Linq (which I already had but did again) and to make sure debug="true" in my compilation tag and target framework in my compilation tag was the same as the target framework for the project which I did (both are .NET 4.0). I am still getting the error and I have no clue on how to proceed from here.
The error is thrown on the following line of the Conditions.dbml file:
using System.Data.Linq;
Add a reference to the System.Data.Linq assembly. Right click the References folder in your project, go to Add Reference, then make sure you're on the Assemblies tab and add a checkmark next to System.Data.Linq. (These directions are for VS 2013).
Yesterday I found myself dealing with the following problem:
Wierd JSON result - Elfinder.NET initialization error . The solution that questions suggests did not work for me though.
After significant stepping through code I discovered the JsonResult object was being put together just fine, but when my controller fetched it from the class in the elFinder assembly that put it together, my debugger did not seem to know it anymore. All it could show me was the name of the underlying type; none of the properties showed. I verified that
System.Web.MVC assembly versions matched
Newtonsoft Json.net assembly versions matched
bitness matched
Eventually I moved all of the classes in the elFinder assembly into the main web assembly, and everything was peachy keen.
So, what causes an object to lose all of its state (or makes its state unreadable) without any compiler errors or runtime errors or, well, anything? How could I have fixed this without making everything one big assembly?
I've put together a c# console app that runs a web service intending to download a simple pdf document. I can return the object however I can't seem to be able to figure out how to save the pdf object to file.
ServiceName.ImageResponse responseObject = Response.GetDocument(12345);
MemoryStream ms = new MemoryStream(responseObject.Document);
//System.Drawing is the problem (namespace can't be used in a Web Service)
System.Drawing.Image Img = System.Drawing.Image.FromStream(ms);
Img.Save("c:\\saved.JPG");
This is not compiling as I'm receiving (a red squiqly line under System.Drawing and) the following error:
Error 1 The type or namespace name 'Drawing' does not exist in the namespace 'System' (are you missing an assembly reference?)
http://msdn.microsoft.com/en-us/library/system.drawing.aspx states the following:
Caution noteCaution
Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components.
I would simply like to know if there is another way. I can't seem to figure it out.
trebuchet is probably correct. Check to make sure that you have actually done the work of adding a reference to the required dll. Namespaces do not have a 1 to 1 correspondence to .dll files, for what it is worth.
As to this:
Classes within the System.Drawing namespace are not supported for use
within a Windows or ASP.NET service. Attempting to use these classes
from within one of these application types may produce unexpected
problems, such as diminished service performance and run-time
exceptions. For a supported alternative, see Windows Imaging
Components.
I don't know for certain, but my guess is that several of the components within the System.Drawing namespace expect the process to have access to a window station, the desktop, etc., which is where you would see run-time exceptions. I'd take a punt and see if it works (once you've fixed your compilation error). What they're really saying here is "don't call us if this breaks" :)
I get the following as a warning during build of my asp.net application:
The predefined type
'System.Runtime.CompilerServices.ExtensionAttribute'
is defined in multiple assemblies in
the global alias; using definition
from 'c:\Program Files\Reference
Assemblies\Microsoft\Framework\v3.5\System.Core.dll'
How do i resolve this warning?
From this blog:
So the final solution was to use the InternalVisibleTo attribute in one
of the assemblies. This means
ExtensionAttribute only needs to be
defined in one assembly. There's more
info here on how to do that with
strongly named assemblies since it's
not completely straight forward.
Related question: C# Compiler Warning 1685
from MSDN
Visual C# Reference: Errors and
Warnings Compiler Warning (level 1)
CS1685
Error Message The predefined type
'System.type name' is defined in
multiple assemblies in the global
alias; using definition from 'File
Name'
This error occurs when a predefined
system type such as System.int32 is
found in two assemblies. One way this
can happen is if you are referencing
mscorlib from two different places,
such as trying to run the.Net
Framework versions 1.0 and 1.1
side-by-side.
Based on this, we probably need to see the list of assemblies and their references to help you much.