Assembly reference not resolving in the Web.config - wcf

I am developing WCF service hosted by IIS. I need to add KnownType attribute to my base class. One way of adding KnownType attribute is to add a section into the Web.config file like this:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="MyBase, MyBaseDll">
<knownType type="MyDerived, MyDerivedDll"/>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
But I got error message when my mouse is over the MyBase. The Error message is “Invalid Module Qualification: Failed to resolving assembly MyBaseDll”. Same error message for MyDerivedDll.
Additional information:
Both MyBaseDLL.dll and MyDerivedDLL.dll are in the IIS /bin folder. Both DLLs reference no other assembly other than .net system assemblies

Have you tried giving the full name of the assemblies and full name of the types (namespaces and all) ...
<add type="MyNamespace.MyBase,
MyBaseDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX">
<knownType type="MyNamespace.MyDerived,
MyDerivedDLL, Version=v.v.v.v, Culture=neutral,
PublicKeyToken=XXXXXX"/>
</add>

What happens when you run the service? The error message could be bogus. For instance, ReSharper sometimes gets confused about assembly references in config files.
OTOH, other times, it's correct.

Related

Could not load file or assembly 'Microsoft.AspNet.Web.Optimization.WebForms' or one of its dependencies. The system cannot find the file specified

I can't find anything to resolve this and have tried multiple things.
Task: I am trying to add bundles to an old existing web project. I have added everything I need I believe as I have done the same in a new project and it works.
<webopt:BundleReference runat="server" Path="~/bundles/masterstyle" />
This seems to be where the issue has started with this line above. I installed via nuget the web optimization webforms package which fixed the squiggly line under webopt. However, now, I am getting 2 issues.
BundleReference has a squiggly line saying "Element
'BundleReference' is not a known element/ This can occur if there is
a complication error in the Web site, or the web.config file is
missing".
It also can't seem to find the package I have just installed which
is "Could not load file or assembly
'Microsoft.AspNet.Web.Optimization.WebForms' or one of its
dependencies. The system cannot find the file specified".
If anyone can help resolve this, it would be greatly appreciated. Been stuck on it for 4 hours now.
Here is the likely relevant stuff in my web.config file:
<pages>
<namespaces>
<add namespace="System.Web.Optimization"/>
</namespaces>
<tagMapping>
<add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="we3.Site.Form" />
</tagMapping>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
</controls>
</pages>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Install it from nugget: https://www.nuget.org/packages/Microsoft.AspNet.Web.Optimization.WebForms/
Install-Package Microsoft.AspNet.Web.Optimization.WebForms
Or you can manually download it from: https://www.nuget.org/api/v2/package/Microsoft.AspNet.Web.Optimization.WebForms/1.1.3
and add it as reference to your project (unzip first the .nupkg file)
Installing the package Microsoft.AspNet.Web.Optimization is what resolved this for me.
Install-Package Microsoft.AspNet.Web.Optimization

The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime" from TeamCity

I'm getting the above error from our TeamCity build.
I have tried adding the following lines to the web.config.
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
I have also installed the latest Windows SDK for .NET4.5.2.
Neither of these have resolved the error.
Any ideas?
Finally found a solution to this problem. I added a reference to the System.Runtime.dll assembly to my project. I added a reference to the following file to my project (substitute your own version of .NET in the path as necessary). You could always copy the file to your project folder and link it from there as an alternative.
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades
This worked for me and hopefully will work for someone else.

Error Loading ASP.Net Profile

I have an existing MVC 4 application that uses the AspNetSqlProfileProvider, configured like this:
<properties>
<add name="MyTypeAs"
type="System.Collections.Generic.List`1[[My.Namespace.MyTypeA, My.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" serializeAs="Binary" />
</properties>
Now I wish to update the system (without removing the old profiles) like this:
<properties>
<add name="MyTypeAs"
type="System.Collections.Generic.List`1[[My.Namespace.MyTypeA, My.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" serializeAs="Binary" />
<add name="MyHashOfInts"
type="System.Collections.Generic.HashSet`1[System.Int32]" serializeAs="Binary" />
</properties>
I have had no problem adding additional properties in previous projects. If the serialized data was from a previous version where the additional property was not defined, loading that property
yielded default(T). However, with this change, when my controller executes this line:
List<MyTypeA> myTypeAs =
(List<MyTypeA>)HttpContext.Current.Profile.GetPropertyValue("MyTypeA");
an Exception is thrown:
Attempting to load this property's type resulted in the following error: Could not load type 'System.Collections.Generic.HashSet`1[System.Int32]'.
Notice that I'm referencing a property of type List<MyTypeA> but the Exception says it cannot load the type
System.Collections.Generic.HashSet`1[System.Int32].
Did I make a mistake in how I specified the type in web.config? Is there another cause?
All of this is happening in Visual Studio 2010 SP1 with the .NET 4 runtime selected.
It turns out that, different from List<T>, HashSet<T> requires a fully qualified assembly name.
System.Collections.Generic.HashSet`1[[System.Int32]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Sharepoint 2010 register control as safe through wsp

I created a "Hello World" Sharepoint 2010 solution using VS2010. It contains just a feature, and a webpart containing a label. I registered the webpart as a safe control in the "Properties" window of the webpart, in VS2010.
When I deploy my solution to my local server, everything works great! I can add the webpart to a page, and in the web.config file my control is added to the SafeControls list. When I install the same solution on a different server, I can see the webpart in the list of available webparts, but when I try to add it to the page, it tells me that it's not registered as safe. When I check the web.config file, there is no entry for my control. If I add one manually (the one from my dev server), things start to work.
Now, I wonder why the control is not registered when I install the wsp file. The manifest inside the wsp contains this line:
<Assemblies>
<Assembly Location="abc.TestWebPart.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl Assembly="abc.TestWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e262c75e6f6e8440" Namespace="abc.TestWebPart.VisualWebPart1" TypeName="*" />
</SafeControls>
</Assembly>
Any ideas are very welcomed!
Check for typos and version differences.
Did you activate the feature for the web app?
Late answer I know.
I think you are missing ' Safe="TRUE" ' in your SafeControl Tag.
Correct code:
<Assemblies>
<Assembly Location="abc.TestWebPart.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControls>
<SafeControl
Assembly="abc.TestWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e262c75e6f6e8440"
Namespace="abc.TestWebPart.VisualWebPart1"
TypeName="*"
Safe="TRUE"
/>
</SafeControls>
</Assembly>
</Assemblies>

MSBuild: building website using AspNetCompiler - adding references?

I'm attempting to build a ASP.NET website using MSBuild - specifically the AspNetCompiler tag. I know that, for my project, I need to add some references. Within Visual Studio I have several references, one is a project reference and the others are some DLLS (AjaxControlToolkit etc). I'm happy not referencing the project and referencing the DLL instead - however I just can't work out how to add a reference. I've looked up and down and this is what I've found so far:
<Target Name = "PrecompileWeb">
<AspNetCompiler
VirtualPath = "DeployTemp"
PhysicalPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\WorkingDirectory\VSS"
TargetPath = "D:\AutoBuild\CruiseControl\Projects\Websites\MyCompany\2.0.0\PreCompiled"
Force = "true"
Debug = "true"
Updateable = "true"/>
</Target>
Also - I've picked up this bit of code from around the web somewhere, which I thought might help:
<ItemGroup>
<Reference Include="My.Web.DataEngine, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\AutoBuild\CruiseControl\Projects\Components\My.Web.DataEngine\bin\Debug\My.Web.DataEngine.dll</HintPath>
</Reference>
</ItemGroup>
What I want to do is add a attribute to the AspNetCompiler tag, something like:
References="#(Reference)"
but MSBuild isn't very happy about this.
I've been a bit stuck in not being able to find decent references on doing this anywhere: so I'd really apprechiate some pointers or reference material etc. (or just the answer!)
Thanks for you help.
-tom
The aspnet_compiler tool doesn't have a reference property.
Have you looked at using Web Deployment Projects (2005 version)?
You can add references to assemblies used during the compilation of an ASP.NET application by adding to the <assemblies> element, under <compilation> if your web.config. For example:
<compilation targetFramework="4.6.2" debug="true">
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
Read more here: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bfyb45k1(v=vs.100)