When trying to deserialize using the ComponentSerializationService, errors are populated that references were not found:
public ICollection Deserialize(object serializationData)
{
var serializationStore = serializationData as SerializationStore;
var componentSerializationService = _serviceProvider.GetService(typeof(ComponentSerializationService)) as ComponentSerializationService;
var collection = componentSerializationService.Deserialize(serializationStore);
}
Errors such as :
Could not find type 'System.Drawing.Size'. Please make sure that the
assembly that contains this type is referenced. If this type is a
part of your development project, make sure that the project has been
successfully built using settings for your current platform or Any
CPU.
Here I've passed through a Button control and set the size property.
I remember that I had this "could not find type System.Drawing.Size" some time back and that I spent way too many hours fixing it. I don't really remember what it was that finally fixed it and I don't think that choosing Any CPU is a problem at all. Although it wasn't the very same context as yours I still think it's worth trying the following since it could be a problem connected to referencing different versions of the System.Drawing.dll from several projects inside your solution.
Thus, try double checking the solution for inconsistencies in the versions used (even if the packages.config entries are looking ok) and make sure they all are referencing the same version (.net461 for example).
In my case, some of the 30+ libraries in the solution turned out to be using .net45; I used a tool called Target Framework Migrator to fix this. You can get it through Tools => extensions and updates => Online => Visual Studio Gallery
and then type Target Framework Migrator in the Search Field.
I do remember, that I also upgraded .Net to 4.6.1 during my attempts to fix the problem ... maybe you could try this too ... but in any case running the Target Framework Migrator for your own Libraries (and restarting VS 2015 on the way) is definitely worth a try.
Good luck!
Related
This is most unusual for me.
This code has always worked (several years), just recently I started getting this error:
Method not found:
Void Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider..ctor(System.String, System.Data.SqlServerCe.SqlCeConnection)'.
One of the main changes that I thought might have caused it was changing the target framework to .Net 4.6. But after changing back to 4.5.2, this is still an issue.
I am calling a class using this line:
e.Result = SyncLogic.Synchronize(e.Argument.ToString());
It doesn't enter this class (SyncLogic), however, and I assume the conflicting line is this:
orch = new SyncOrchestrator
{
RemoteProvider = new SqlSyncProvider(scopeName, sqlServerConn),
LocalProvider = new SqlCeSyncProvider(scopeName, sqlCeConn),
Direction = SyncDirectionOrder.Download
};
I have the same app installed (on my dev pc) and it works fine. Using a disassembler it appears to be using the same version of Microsoft.Synchronization.Data.SqlServerCe, which is 3.1.0.0, Runtime Version v2.0.50727.
So I don't know how the same assembly could work for one build but not another.
Thanks in advance!
This answer is actually a workaround rather than a solution. I don't know why had this problem, but I figured out that before my HD crashed the code worked. It was when I had to rebuild the project (because I lacked a recent backup) that the error started occurring.
The workaround was taking the older project, one that worked, keeping the references intact and copying in new code until it was up to date. So now I'm back in action but I really wish I knew why that error was happening since the references seemed to be identical. I need to let go of this anomaly and get on with life. Thanks for reading and learning this great moral lesson... keep your projects backed up!
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.
As simple as title really.
I've upgraded a solution from .Net 2-3.5 to .Net 4, it worked fine, I've then installed VS 2012 and with it .Net 4.5 and I'm now getting an ExecutionEngineException when trying to reflect the CustomAttributes from a dynamically generated DLL using the following code:
Assembly assembly = Assembly.LoadWithPartialName("DavesNamespace.Custom");
var attributes = assembly.GetCustomAttributes(typeof(ChecksumAttribute), true);
I get the exception with or without the Type specified for GetCustomAttributes, but it's only at that point that it throws the exception, the assembly is successfully loaded and I can actually view the CustomAttributes collection if I stick a break point in.
The original .Net 2-3.5 version still works since having installed vs2012.
Any help much appreciated, I have found a few issues stemming from vs2012 ending with ExecutionEngineExceptions looking online, but nothing with an answer.
The problem can be resolved by removing VS2012 and .Net 4.5, but as we're intending to move to VS2013 company wide when it's released that's not really a solution.
EDIT:
Have got the error occuring in a sample app which does just this, and the exception is still thrown even if the application is built targetting 4.5
Stack trace added in the comments below (It's null)
I have resolved the issue for our particular situation, although I think the root is an undocumented change in how .Net 4.5 reads CustomAttributes on DLLs.
The solution was moving a CustomAttributeBuilder being set from being the last thing before AssemblyBuilder.Save() [After all the content of the assembly has been populated] to the first thing after AppDomain.CurrentDomain.DefineDynamicAssembly() [Before any of the content has been populated]
The actual code where the exception was being thrown hasn't needed to change, although I have refactored to use the replacement for LoadWithPartialName() which is just Load(), this workaround still worked with LoadWithPartialName() though.
It may be that adding a custom attribute after the content of the assembly puts the custom attribute in the wrong place? But the issue is logged with MS to look into.
output type of 'Class Library', and a target framework of '.NET Framework 4'.
According to everything I've read, I should have it available, but all I'm seeing in the System.Runtime namespace is the following:
CompilerServices
ConstrainedExecution
ExceptionServices
Hosting
InteropServices
Remoting
Serialization
Versioning
Any ideas?
You just need to add a reference to the System.Runtime.Caching assembly.
In solution explorer, right-click on "References"
Select "Add reference"
From left side menu select "Assemblies"
Look for (or filter) and add System.Runtime.Caching.dll.
It's not part of the default set of references in a class library, but you should be able to add it with no problems.
To complement Jon Skeets answer, (for those who run into this problem), if you still get red squiggly lines under Caching after having added reference to System.Runtime.Caching assembly, just restart the Visual Studio, after having saved the solution, and you should be good to go.
Having added the reference, saved the solution and ( if need may be ) restarted Visual Studio, you should be able to use the types within this namespace. In order to get my solution to work, I had to do this very way.
Edit:
While trying to recreate the problem, and solving this way, it seems that we need to set Copy Local to True in System.Runtime.Caching > Properties and then restart Visual Studio for getting it to work. At least, for my case, the problem didn't seem to solve without this. ;)
Reference System.Runtime.Caching.dll. This is another one of those rather obtuse gotchas in the .NET framework right now where there will be very similar namespaces in some things, but the actual classes you want will be referenced in different assembles. As an example, CacheItem is in this alternate DLL, whereas ApplicationActivator (in System.Runtime.Hosting) is in mscorlib.
For me the System.Runtime.Caching NuGet package is what I needed
little bit o this and all was well
dotnet add package System.Runtime.Caching --version 5.0.0
Today after deploying some changes to a C# MVC site that I run, I went back to make some more modifications and came across this error:
Missing compiler required member System.Runtime.CompilerServices.ExtensionAttribute..ctor
The error is a bit vague (other than it's description, obviously) as it doesn't give me a file, line, or column to reference, only the project. Also, it throws the error a total of 20 times. I only made three changes to the code between the time I deployed (it was completely functional at that time) and now. I reverted my changes and it is still throwing the same error which makes no sense to me.
I haven't found a lot of information on this error on SO or Google, other than this guys solution and a couple references to some Mono project errors (I'm not using Mono). The solution the guy above gives requires adding a class definition that will allow the compiler to resolve the reference. I don't particularly want to do this because I haven't needed to do it up until this point and it will just muddy my code.
Just curious if anyone has run across this before.
In my case it was because the project was not referencing Microsoft.CSharp. Once I added a reference to that assembly, it compiled just fine.
I don't know if anyone else has experienced this, but I suddenly ran into this error after adding some code utilizing dynamic types and incorporating WebAPI into a project that originated as a TypeScript application in VS2013. Simply adding a reference to Microsoft.CSharp resolved my issue.
Hope this helps someone else.
This error usually means either your project is compiling against .NET 2.0 or you aren't referencing the correct version of System.Core.dll
For a near duplicate question, see Error when using extension methods in C#
I ran into this situation as well today. In my case I was referencing the Newton.Json.Net dll v3.5 in my .NET 4.0 application. I realized that I wasnt even using this library, thus once I removed it from my references, it no longer gave me the compiler error.
Problem solved!!!
The actual error comes from the fact that your 2.0 assembly that causes the error contains this code:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
The Code Above allows the .NET 2.0 Assembly to use extension methods (see Using extension methods in .NET 2.0?). While it confuses the compiler if you target .NET 4.0 and reference a 2.0 Assembly (containing above code) as the mscorlib.dll(4.0) contains the same class in the same namespace.
I fixed this
by compiling the original 2.0 assembly again without the attribute targeting 4.0
by removing the assembly (obviously)
by adding a third Extension Attribute in the target you compile (it seems to overrule the referenced definitions)
Writing this code somewhere in your project may solve your problem. It works for me
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
Probably you use dynamic keyword In .NetStandard Class library project. If so, you need to add a reference to Microsoft.CSharp library in the project. Hope it will resolve your problem.
NLog.dll 2.0 referenced from a .NET 4.0 project can cause this too.
I don't have a correct solution, but I'll add my data point:
In my case the error is caused by referencing GoogleSearchAPINet20
Here is what happens:
I close the solution that builds
I open the solution again. It still builds
As soon as I make any change and try to build, I get 19 "Missing compiler required member ..." errors
I remove the reference to GoogleSearchAPINet20
I add back the reference to GoogleSearchAPINet20
I build the solution. It builds without errors
I can now make code changes, build or perform any other actions with solution correctly as long as my Visual Studio is open
I close Visual Studio
Repeat from step one
I'm not referencing System.Core.dll in my solution at all and my target framework is .NET 4.
I'm a bit annoyed at this point ...
Got this error when trying to use async Tasks against .NET 4.0. Updating Target Framework to 4.5.2 fixed the problem.
I hit the same set of exceptions after I added some async methods to a winforms project. I needed to bump my .NET version from 4 to 4.5
For me, the problem occure when I add asynchronous method with async Task await in my .net4.0 project !
With previous versions of the .NET-Framework 4.5, you must install this package:
Install-package Microsoft.Bcl.Async –pre
or
Install-Package Microsoft.CompilerServices.AsyncTargetingPack
more info on Nuget or Nuget