System.ComponentModel.DataAnnotations version reference issue on Schema - c#

I am working with an application that uses System.CodeDom.Compiler to generate Silverlight client DLL's for use in referencing entity framework entities. My machine generates errors during the compilation process. It is not finding System.ComponentModel.DataAnnotations.Schema. This is not a .net v4 for construct. My machine we had upgraded to Silverlight 5 and discovered an incompatability with Silverlight 5 and had to return to Silverlight 4. Other machines that were never attempted to upgrade to Silverlight 5 do not exhibit this issue. The code explicitley includes a reference to System.ComponentModel.DataAnnotations when certain dataannotations are required. I have not been able to expunge this dependency to a version of the System.ComponentModel.DataAnnotations namespace that appears to be more advanced than my machine should have. I can not move forward in version as I must remain compatable with an automated build process that distributes the results of my work to clients. If I change the reference systax to work for me it will fail for everyone else. I need ideas as to how to identify the source of this so that I can eliminate it. The references within my project show correct versions, but since this compilation is done on the fly outside of my solution I do not know how I can verify the version used in the application generated compilation done later. I have trapped the error at the time it occurs, but that is not helpful, as it is providing a list of the references by name at compile time and I do not know how it resolves to the particular dll's to use at that time, and it does not appear to be finding the one I think it should or it would not be referencing the .schema namespace. Something I do not have a handle on is forcing in this reference. I think this means I have something on my machine using an entity framework reference later than v4.3 but I think my machine has only v4.I am looking for thoughts on how I can track this down.
I have done many generic searches on this problem, finding many references to this particular error, some of which are on this site, that indicate I need to be looking for a problem with the versions of the DLL's, but I am not sure where the compilation is pulling the dll's from and the ones I have checked appear to be the correct version for the namespace System.ComponentModel.DataAnnotations so I think my problem must be being picked up from something else.
There are 2 not specifically Silverlight 4 assemblies listed as inputs to the compiler. My two source files do not cause the reference, so I think if must come from one of these.
...\bin\RIAServices\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.dll
...\bin\RIAServices\v1.0\Libraries\Silverlight\System.ServiceModel.DomainServices.Client.Web.dll
The actual error generated is:
The type or namespace name 'Schema' does not exist in the namespace
'System.ComponentModel.DataAnnotations' (are you missing an assembly
reference?) with an additional tage of: error CS0234.
Most posted solutions involve an upgrade to a later version of Dot Net and/or Entity Framework and those are not available to me.
I am no expert on Entity Framework or RIA Services and may be overlooking something fundamental.

Related

Decompiling .NET assemblies only shows throw null; [duplicate]

I have a project that uses System.Runtime.Serialization assembly. I am using the type DataContractSerializer from that assembly, but I have a problem.
There are two assemblies:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Runtime.Serialization.dll
C:\Windows\Microsoft.net\Framework\v4.0.30319\System.Runtime.Serialization.dll
Both of them have the same version - v4.0.30319. The first one have 429kb size, and the second one 1037kb. I used reflector to see the list of classes, and the first one doesn't have the class that I need (DataContractSerializerSettings). However, the second one does have it.
Why are there some big difference in size and classes for that assembly? Will it be ok, if I use the second one, instead of the first?
.NET version 4.0 made a big change in the way framework reference assemblies are done. Previously, the reference assembly was a simple copy of the runtime assembly, the one stored in the GAC. That however caused some painful problems. Notable is the WaitHandle.WaitOne(int) overload, it was added in the .NET 2.0 Service Pack 2 update (aka .NET 3.5). Programmers used it without noticing that it was an added method, the mscorlib assembly version number was still 2.0.0.0. But then discovered their program failed when running on an unpatched version of .NET 2.0. Very nasty kaboom, MissingMethodException without a hint why such a common method could be missing.
To prevent this kind of breakage, the .NET 4.0 reference assemblies are kept separate, in the "%programfiles%\Reference Assemblies" directory as you found out. And they are special assemblies, they only contain the metadata with all the IL stripped out. Which is why the assembly is so much smaller.
Microsoft now can improve the .NET 4 code and add public classes and methods without causing this kind of breakage. And have done so profusely, updates 4.01, 4.02 and 4.03 have shipped since the original 4.0 release.
The reason you are having trouble with the DataContractSerializerSetting class is thus easily explained, it just doesn't appear in the reference assembly. It got added, probably in one of those incremental updates. And you should not try, your program will break on a machine that doesn't have the update. You should wait until .NET 4.5, the version that added it to the reference assembly. You can invoke DLL Hell if you really want to.

I am *not* missing an assembly or reference

I'm using Visual Studio 2013, and I'm getting an error in my C# code that I can't figure out. I'm working with the Microsoft Kinect SDK, but I'll keep it general.
I downloaded the SDK, and I can get the included sample programs to build and run. But when I try to use the code in my own project, I get the
Type or namespace name 'Kinect' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference)
error.
The thing is, I'm not missing an assembly or reference. I have it added to the project's references, and the path is valid. Also, the using statements at the top of the file will autocomplete to "Kinect" for me. If I start typing using Microsoft., Kinect will appear as an autocomplete option.
What are the steps to debugging an error such as this? Could it be a 32/64 bit issue? I tried using Dependency Walker to look at the Kinect DLL, and while it throws some errors (Error: Modules with different CPU types were found.), it doesn't show any issues that I don't see with other DLLs that I'm using successfully.
What are some other potential issues that might cause a problem with DLLs not being recognized?
1 - Try going to your project settings and verify the version of the .NET framework it uses.
The best to do is to choose the same version as the external libraries.
If it's a client profile, it will very often bring that exact problem. (I'm not sure what the client profile is, but I ended up never using it...)
2 - Check if any of your references got an exclamation mark.

After downloading swagger.net to web Api project I get error as Assembly generation failed

I have installed SwaggerUI for .Net from Nuget package and trying to test web api methods with the swagger. But I am get below compile time error.
Error Assembly generation failed -- Referenced assembly 'WebActivator' does not have a strong name
When I change the solution settings for signing property from checked to unchecked I don't get this error. Now I don't want to change any settings that are made to signing property of solution settings and fix this error.Can any one please help me to fix this error?
Your assemblies are strong named while the new assemblies you referenced recently are not. And more than this, they are not compiled from source (you got them via NuGet).
Two workarounds cross my mind now:
Get the sources for SwaggerUI and dependecies and sign them with your key. I think this is a tedious process, since you need to build everything.
Use the DLLs like now and sign them after each build. For example you can use these instructions (dissasemble, sign & re-assemble). If you do this, I think it's worth adding this as a pre-build step to your least-dependent project (the one that builds first).
I have also found this - Assembly Strong Naming Toolkit (for NuGet). Never tried, but maybe it's worth looking into as it seems to be designed for your case.

Entity Framework 4 issue

Using .NET Web API (.NET 4, EF 4) and I'm getting some strange errors when debugging and really can't figure what is going on.
Say in the DocumentRepository I have this constructor:
public DocumentRepository(DocPortalContext db)
{
this._db = db;
}
If I debug and hover over _db and drill into the items in the popup window I'm coming across the following errors:
System.Data.Entity.Infrastructure.IObjectContextAdapter.ObjectContext = 'System.Data.Entity.DbContext' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.DbContext' could be found (are you missing a using directive or an assembly reference?)
and
System.Collections.Generic.ICollection>.IsReadOnly = 'System.Collections.Generic.Dictionary' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.Generic.Dictionary
No exceptions are being caught.
If I put a break point on this line in a repository method - return _db.Documents.AsQueryable(); - and hover over Document I get the following error:
System.Linq.IQueryable.Provider = 'System.Data.Entity.Infrastructure.DbQuery' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Data.Entity.Infrastructure.DbQuery' could be f...
Some help would be much appreciated.
Additional information:
Drilling into _db in the following way gives message quoted at the end:
base(System.Data.Entity.DbContext) -> Internal Context -> _appConfig -> and finally Default Connection Factory has the following error beside it "The function evaluated requires all threads to run."
More information as per my comment:
This isn't really related to the question, but it has me thinking there could be something wrong with my install of .NET or VS - I don't know enough about the pipework to make that call, maybe one of you can. Anyway, I can browse to a URI in my WebAPI project and get JSON returned in the browser. When I try to consume the URI in my Website project, I get this in my browser: Could not find file 'C:\Program Files (x86)\IIS Express\System.Net.Http.StreamContent'. which is also caught as an exception.
By default EF 4 generates proxy classes on the fly that inherit from your POCO classes or your model first classes. That is most likely why you get these errors on runtime. The odd things is that all required usings should be included.
Are you sure you reference System in your POCO classes (presuming you have POCO classes)?
Do all projects in your solution have the same .NET version setup in project's properties?
Do those versions agree with the version on the MSDN describing the missing classes?
Try registering your entity-framework dll and sql-server dll in global assembly cache using gacutil.exe from visual studio command prompt
I had come across this issue recently on a small sample application where we just included nuget packages and created some data layer objects. This is what we did and it solved the issue
Make sure temp folders for .net are clean . usually in asp.net temporary files in windows directory.
Make sure your visual studio is upto date and not requiring a restart due to nuget reinstall. Not sure if it solved or did help but i checked this as well and restarted vs.
Clean the projects and made sure that dlls are present. if you are using some webmatrix dll for asp.net simple membership make sure you have selected to copy it locally. This was one issue when we were seeding data for roles and members for mvc4 simple membership use but may not be the case for your project.
We also checked that in web projects the configuration for ef corresponds to proper version of ef.
Build the solution and run it after a vs 2012 restart and it worked fine. Now I dont know exactly which of these things helped in resolving this issue but doing all 4 worked in one case.
Just thought to share if it helps.
These look like issues relating to an incompatibility between your project's target .Net version and the build version of the assembly you're referencing.
In this instance, you should make sure that the assembly you are referencing is less than or equal to your project's target .Net Framework version.
I have seen this message numerous times. 9 times out of ten, this means that there is a likely problem with the App.config file. Usually, it is just missing. In other words, for every project folder you have referencing the Entity Model you need to place a copy of that App.config file within it. If they are already there, then delete the App.config file that partners the edmx file, and recompile the Entity Model separately to regenerate it. (DON'T DELETE THE EDMX FILE or THE DESIGNER CLASS) Then you have to replace all the App.config's again. Yes, it sucks!!! Sometimes, LinqPad is great for checking this issue too. You can reference the dll file in LinqPad and attempt to run queries giving you the same error message letting you know that the problem is not just Visual Studio.
Hope this helps...Good Luck!!!!
How are you implementing your repository? Seems to me that maybe the problem is that your application is running on a different thread than your repository and that might be the answer for the "The function evaluated requires all threads to run." message.

The type or namespace name could not be found [duplicate]

This question already has answers here:
Getting "type or namespace name could not be found" but everything seems ok?
(44 answers)
Closed 8 years ago.
I have a C# solution with several projects in Visual Studio 2010.
One is a test project (I'll call it "PrjTest"), the other is a Windows Forms Application project (I'll call it "PrjForm"). There is also a third project referenced by PrjForm, which it is able to reference and use successfully.
PrjForm references PrjTest, and PrjForm has a class with a using statement:
using PrjTest;
Reference has been correctly added
using statement is correctly in place
Spelling is correct
PrjTest builds successfully
PrjForm almost builds, but breaks on the using PrjTest; line with the error:
The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?)
I've tried the following to resolve this:
Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot)
Removed and re-added the reference and using statement
Recreated PrjForm from scratch
PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder
Loaded the solution on a different computer with a fresh copy of VS 2010
I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet.
What else could I try?
See this question.
Turns out this was a client profiling issue.
PrjForm was set to ".Net Framework 4 Client Profile"
I changed it to ".Net Framework 4", and now I have a successful build.
Thanks everyone!
I guess it figures that after all that time spent searching online, I find the solution minutes after posting, I guess the trick is knowing the right question to ask..
In my case I had:
Referenced DLL : .NET 4.5
Project : .NET 4.0
Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. I recompiled the .DLL to target .NET 4.0 and I was fine.
PrjForm was set to ".Net Framework 4 Client Profile" I changed it to ".Net Framework 4", and now I have a successful build.
This worked for me too. Thanks a lot. I was trying an RDF example for dotNet where in I downloaded kit from dotnetrdf.
NET4 Client Profile:
Always target NET4 Client Profile for all your client desktop applications (including Windows Forms and WPF apps).
NET4 Full framework:
Target NET4 Full only if the features or assemblies that your app need are not included in the Client Profile. This includes:
If you are building Server apps, Such as:
ASP.Net apps
Server-side ASMX based web services
If you use legacy client scenarios, Such as:
o Use System.Data.OracleClient.dll which is deprecated in NET4 and not included in the Client Profile.
Use legacy Windows Workflow
Foundation 3.0 or 3.5 (WF3.0 , WF3.5)
If you targeting developer scenarios and need tool such as MSBuild or need access to design assemblies such as System.Design.dll
Another thing that can cause this error is having NuGet packages that have been built with a newer version of .NET.
The original error:
frmTestPlanSelector.cs(11,7): error CS0246: The type or namespace name 'DatabaseManager'
could not be found (are you missing a using directive or an assembly reference?)
Further up in the log I found this:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3275: The primary reference "[redacted]\DatabaseManager\bin\Release\DatabaseManager.dll" could not be resolved because it has an indirect dependency on the assembly "System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
The solution was to re-install the NuGet packages:
http://docs.nuget.org/docs/workflows/reinstalling-packages
I solved mine because the other project was coded with .NET 4.5 and the other one was coded 4.0
The using statement refers to a namespace, not a project.
Make sure that you have the appropriately named namespace in your referenced project:
namespace PrjTest
{
public class Foo
{
// etc...
}
}
Read more about namespaces on MSDN:
Using Namespaces
I encountered this issue it turned out to be.
Project B references Project A.
Project A compiled as A.dll (assembly name = A).
Project B compiled as A.dll (assembly name A).
Visual Studio 2010 wasn't catching this. Resharper was okay, but wouldn't compile. WinForms designer gave misleading error message saying likely resulting from incompatbile platform targets.
The solution, after a painful day, was to make sure assemblies don't have same name.
It is also possible, that the referenced projects targets .NET 4.0, while the Console App Project targets .NET 4.0 Client Library.
While it might not have been related to this particular case, I think someone else can find this information useful.
The compiled dll should have public Class.
I had the same issue. The target frameworks were fine for me. Still it was not working.
I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. Then it started working for me.
Other problem that might be causing such behavior are build configurations.
I had two projects with configurations set to be built to specific folders.
Like Debug and Any CPU and in second it was Debug and x86.
What I did I went to Solution->Context menu->Properties->Configuration properties->Configuration and I set all my projects to use same configurations Debug and x86 and also checked Build tick mark.
Then projects started to build correctly and were able to see namespaces.
Changing the framework to
.NET Framework 4 Client Profile
did the job for me.
For COM/ActiveX references, VS 2012 will show this error right on using statement. Which is quite funny, since it's saying that may be you are missing a using statement.
To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug.
If your project (PrjTest) does not expose any public types within the PrjTest namespace, it will cause that error.
Does the project (PrjTest) include any classes or types in the "PrjTest" namespace which are public?
just changed Application's target framework to ".Net Framework 4".
And error got Disappeared.
good luck;
:D
check your Project Properties, your Reference Paths should be empty like this:
Regards

Categories

Resources