How do I add assemblies to System.Web Assemblies? How do I derive the syntax? - web-config

I'm trying to add a custom HTTP Validator as shown here. I want many sites to share this implementation as an external library. That way as I discover newer/better ways to handle validation, I can update the linked assembly and update all related projects.
When I take my class and place it in my web project, all I have to do is add this line and everything works:
<system.web>
<httpRuntime requestValidationType="SampleRequestValidator"/>
However... when I try to reference an external assembly, IIS complains saying that it can't load the type.
Question
Can someone tell me if I need to add my custom type to this section of web.config:
Line 28: <compilation debug="false">
Line 29: <assemblies>
Line 30: <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 31: <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Question2
Can someone tell me the correct way to get the type string to enter? So far I'm using this
Console.Writeline(typeof(SampleRequestValidator).AssemblyQualifiedName)

"Yes" for question one. On my ASP.NET MVC application I also had to add my namespace to web.config:
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="My.Custom.Namespace"/>
</namespaces>
</pages>
What you're doing for question 2 should work... you can also see the assembly name in Visual Studio by right-clicking on the project and going to properties and then looking at the "Application" tab.

Related

ActiveReports WebViewer Looks great in Dev, bad in Staging

I have an ActiveReports WebViewer working great in my development environment. I deployed it to a staging server (Windows 2008 R2 which is IIS7) and I don't get errors, but the viewer looks all crazy. Can anyone point me in the right direction? I've been playing around with HTTP handlers and nothing changes the way it looks. The left pane of the viewer, which can be printing options or report parameters is stretched across the top and the images are broken. Also, the report area that normally displays the report is shrunken up and the report doesn't show. I don't have a high enough rep to post the screen shot, so I hope I have described it enough.
Please ensure that the Web.config on the staging server matches your Web.config on your dev machine ie, please make sure that the Version attribute on each assembly matches the version of your DLLs
<system.web>
<compilation targetFrameork="4.0">
<assemblies>
<add assembly="GrapeCity.ActiveReports.Extensibility.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Diagnostics.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Chart.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Document.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Export.Html.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Export.Pdf.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Export.Image.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
<add assembly="GrapeCity.ActiveReports.Web.v8, Version=8.0.133.0, Culture=neutral, PublicKeyToken=cc4967777c49a3ff" />
</assemblies>
</compilation>
</system.web>
Next, ensure that the DLLs are being published to the bin folder on the staging server as well.
Regards,
Mohita
I figured it out. It was actually a css issue. I am generating the webviewer using JavaScript, like in the Mobile example provided by component one, though I extended it to do things a little differently. I hadn't copied over the css file! Whoops!
Make sure all the assembly references to GrapeCity.ActiveReports are set to Copy Local true.

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'

I got the following error when I used sqlce 4.0 with entityframework 6.0
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'
My app.config looks like this
....
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" >
<parameters>
<parameter value =" System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<!--providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers-->
</entityFramework>
<connectionStrings>
<add name="FbMultipleInsOrderContainer" connectionString="metadata=res://*/FbMultipleInsOrder.csdl|res://*/FbMultipleInsOrder.ssdl|res://*/FbMultipleInsOrder.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=|DataDirectory|\FBMultipleOrderSync.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
...
I tried re-installing EF 6. But no avail.
Any clue on this would be much appreciable.
After installing the EntityFramework.SqlServerCompact nuget package, check that your app.config contains the following (as per #ErikEJ's comment above):
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
(You can leave the line for SqlClient even though you don't really need it.)
ErikEJ has pointed this out, but I'd like to highlight the fact, you MUST remember to install the Nuget package
EntityFramework.SqlServerCompact
I tried following the recommended answer, but didn't realise I didn't have the required NuGet package the App.config was referencing.
I met the issue in my unit tests. The tricky thing was that the error had appeared not constantly.
I managed to solve it by adding the follwing class my my unit tests solution:
public static class Trick
{
public static void FixEfProviderServicesProblem()
{
// this commented line should be used for SQL Server provider
//var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
// this is used for SQL Server CE provider
var instance = System.Data.Entity.SqlServerCompact.SqlCeProviderServices.Instance;
}
}
To achieve this you just need to register the EntityFramework.SqlServerCompact in Package Manager Console,
To do this open power manager console and type below command:
PM> Install-Package EntityFramework.SqlServerCompact
To resolve this problem
Visual Studio Menu -> Tools -> NuGet Package Manager - > Manage NuGet Packages for Solution
Select 'Browse' Tab and search for following 'EntityFramework.SqlServerCompact'
Install it.
It should work.
My issue was the unit tests. You likely only installed the Entity framework for your project, but not your unit tests. To do so:
Right click "Solution" in Solution Explorer (not your project's name)
Click "Manage NuGet Packages"
Search for EntityFramework and press it
You will probably not see a tick next to [Project Name].Tests
This error arose on a User PC. The user ignored a previous error "The ‘DbProviderFactories’ section can only appear once per config file".
Apparently DB2 corrupted the machine config file on her PC, by adding a duplicate (and empty) <DbProviderFactories /> tag.
The solution was to delete the empty duplicate tag. The machine config file is located in [WindowsDir]\Microsoft.Net\Framework[.NET Version]\Config\Machine.config
the solution provided is correct but it does not explain why EF need this assembly. Here is Why...
By default EF's configuration allow you to have a "defaultConnectionFactory" uder entityFramework section. This default factory is configured to "LocalDbConnectionFactory" and its param is "mssqllocaldb".
This factory internally requires "SqlServerCe.4.0" i.e. "SqlServerCompact".
The error happens only if the EF uses its default connection string in DbContext. If EF is provided with some other specified Connection string in your config then this error does not appear. Because EF by default uses the default connection factory.
once you install "SqlServerCe 4.0" the configuration of EF is changed and "LocalDbConnectionFactory" and its param is "mssqllocaldb" are replaced with "SqlServer Ce 4.0". and EF runtime is also able to find the SqlServerCe4.0 Assembly (as it is now part of your references and physically placed in your BIN).
Following is the EF Config before and after installing Sql Server Compact
OLD Config:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
The new configuration is as below:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
and also it added the following section to describe new Factory
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
Don't forget that Package Manager Console takes app.config/web.config from selected as Startup project!
For me, because the programmer is not only one, some programmer is already install EntityFramework.SqlServerCompact, but when I pull in my PC and RUN shows above error message, then I just Uninstall and install again.
Within Visual Studio, all the .dll files that exist in _bin_deployableAssemblies folder need to be set to Build Action : none
All the .dll's for me were set to content.
This is what I set it to, and it worked straight after:
I add the provider code below to the Web.config,and install the EntityFramework.SqlServerCompact package both, and then solve the problem.
If lacking one, it fails.
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact"/>

'compilerVersion' attribute in the provider options must be 'v4.0' or later

Getting this error:
The value for the 'compilerVersion'
attribute in the provider options must
be 'v4.0' or later if you are
compiling for version 4.0 or later of
the .NET Framework. To compile this
Web application for version 3.5 or
earlier of the .NET Framework, remove
the 'targetFramework' attribute from
the element of the
Web.config file.
It was working on our dev system, and we are now deploying to QA using an xcopy type deploy.
We don't have a "compilerVersion" anywhere in the web.config, and the targetFramework is set to "4.0". We have done an IISReset.
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
UPDATE 2: when we removed the entire section, we got past the error. So my question is, what is wrong with leaving in this section if we are on .NET 4.0?
We just did a full xcopy of exactly what was in Test to QA, and in QA it gets the error and DEV doesn't. So the software and configs are identical. Why would it work on one server and not another? IIS options seem to be identical.
taken from: http://www.asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770150
you should go to your server root web.config and include the whole
<system.codedom>...</system.codedom>
tag content into a
<location path="" inheritInChildApplications="false">...</location>
tag
Possible solution here - asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770150
After fighting with this for a while, I ended up creating a new IIS site using a different port and adding my ASP.Net 3.5 application to the new site and it is working perfectly.
I got the same error and found out that my v4.0 website was hosted under the default website that was v2.0. If you've such setup then you need to remove the following line from your web.config:
<compilation defaultLanguage="c#" debug="true" targetFramework="4.0"/>
I hope that helps.

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web'

After converting a Hybrid ASP.NET MVC1 app to MVC2 I'm getting the following error when I try and run the application:
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The allegeded culprit in the web.config file is System.Web.Mvc:
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
So far my investigation seems to lead me to believe that version 2 of System.Web.Mvc is not installed or has not been picked up.
I've tried creating a File > New Project based on MVC 2 and that's picking up the new (v2) version of MVC. I've also converted some other projects (that were not hybrids) and they've converted without problem to MVC2.
I've also uninstalled MVC1 to try and remove references to it from the GAC. However, none of this has worked.
Any ideas?
Make sure you have the binding redirect in your Web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Web.Mvc" />
</dependentAssembly>
</assemblyBinding>
</runtime>
This forces MVC 2 even if MVC 1 is on the machine.
Also: MVC 1 does have a System.Web.Mvc namespace, so make sure you also have:
<assemblies>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
I came across somthing similar and the solution was to change the reference to Microsoft.Web.Mvc so Copy Local was set to True.
I had the same error and clicking the detailed compilation error link in the page showed problems with System.Web.Helpers, .Http, and .WebPages.
After backing up the system I ran update-package -reinstall' and forced an uninstall/reinstall of all packages. This forced the web.config file to be rebuilt correctly and the dependentAssembly sections were constructed right.
After rebuilding the solution it ran first time.
Note, it did add the following bad providers section to the web.config.
<contexts>
<context type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</contexts>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
This only generates a build warning, but I did remove it in favor of the preceeding contexts element.

Tracing is not working on a .NET 2.0 web service

I have a web service written with Visual Studio 2005. My web.config file contains this:
<system.diagnostics>
<trace autoflush="true" indentsize="4" />
</system.diagnostics>
But any call to System.Diagnostics.Trace.WriteLine is ignored. When I step through my code, those lines are skipped over.
Is there another way I should be turning on tracing? How can I tell why tracing is turned off?
I had to add this to my web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
compilerOptions="/d:TRACE"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" />
</compilers>
</system.codedom>
I got that from Microsoft's Troubleshooting Web Services article.