Very strange error: System.InvalidOperationException: Unable to generate a temporary class (result=1). error CS0012

Posts   
 
    
trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 20-Oct-2008 23:58:45   

I am getting the error shown below in an application. It is an asp.net web application (with no reference to LLBLGen, everything is plain datasets)

I am calling a webservice, which calls out to another project, which performs a select from SQL Server into a dataset. No LLBLGen Entity objects are involved, yet I am getting an error which seems to indicate that they are somehow. I am using the the DbUtils.CreateConnection and DbUtils.CreateDataAdapter; see example code below, I have marked the two places they are used.

(BTW, in googling this error there are references to the 'Unable to generate a temporary class ' error being to do with permissions; I have added ASPNET, IWAM?, and IUSR? to my local administrators group, but it had no effect).

Any idea at all??

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Unable to generate a temporary class (result=1). error CS0012: The type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'SD.LLBLGen.Pro.ORMSupportClasses.NET20, Version=2.6.0.0, Culture=neutral, PublicKeyToken=ca73b74ba4e3ff27'.  at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence) at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)  at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence) at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Evidence evidence)    at System.Web.Services.Protocols.SoapServerType..ctor(Type type, WebServiceProtocols protocolsSupported)    at System.Web.Services.Protocols.SoapServerProtocol.Initialize()    at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)  at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) --- End of inner exception stack trace ---
    <WebMethod()> _
    Public Function fGetDataTable(TableName) As DataTable
        Return SQLServer.GetTableAsDatatable(TableName)
    End Function

    Public Shared Function GetTableAsDatatable(ByVal TableName As String) As DataTable
            Dim sql As String = String.Format("select * from {0}", TableName)
            Return SQLServer.GetDataset(TableName, TableName).Tables(0)
        End Function

        Public Shared Function GetDataset(ByVal sql As String, ByVal TableName As String) As DataSet
            Dim ds As New DataSet()
            Using connection As System.Data.Common.DbConnection = SQLServer.GetConnection()
                If sql.Trim.Length < 6 OrElse sql.Trim.ToUpper.Substring(0, 6) <> "SELECT" Then sql = "SELECT * FROM " & sql
                '* --------------------- LLBLGen --------------------------->
                Dim da As System.Data.Common.DbDataAdapter = DbUtils.CreateDataAdapter()
                da.MissingSchemaAction = MissingSchemaAction.AddWithKey 
                da.SelectCommand = New SqlClient.SqlCommand(sql, CType(connection, SqlClient.SqlConnection))
                da.Fill(ds)
                ds.Tables(0).TableName = TableName
            End Using
            Return ds
        End Function

        Private Shared Function GetConnection() As DbConnection
           '* --------------------- LLBLGen --------------------------->
            Return CType(DbUtils.CreateConnection(), SqlClient.SqlConnection)
        End Function

If I bypass the webservice and call this code directly, it works just fine, but calling it via a webservice causes a problem. After the da.Fill(ds) completes, there should be no further interaction with LLBLGen code, should there??

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 21-Oct-2008 09:15:24   

In the WebService, do you reference "SD.LLBLGen.Pro.ORMSupportClasses...dll"?

You should.

trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 21-Oct-2008 16:52:03   

Yes I do.

And I can "View in Browser" the webservice and successfully invoke the webservice from within the browser. It is only when calling it from another project where the error occurs, something related to serialization. Is the fact that I am using an LLB DataAdapter to load the dataset cause non MS standard serialization to occur?

UPDATE:So, I have removed all LLB object usage (GetConnection and CreateDataAdapter) in this code path but am still getting the error.

Also, not sure if it is related, if I try to step into the webservice, I get the error: "Unable to automatically step into the server. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server. See help for more information." (If I don't try to step in, I just get the other error.)

So of course I have set

<compilation debug="true" strict="false" explicit="true">

in the web.config on the web service project and followed all the other troubleshooting steps for that error.

I can create a new webservice class in the same project, and copy and paste the exact same code in from the class that is not working, and I can then both execute AND debug the webservice.

It almost seems like the mere existence of LLBLGen code within the same webservice class, even though it does not execute, is causing a problem somehow.

(Btw, I am running VS2008/3.5 SP1)

Any idea where I would even start looking for the problem? Would it be any help if I uploaded my project?

ANOTHER UPDATE

Ok, I have found the code that causes the webservice to break:

    Public Overloads Shared Sub LoadEntityFromDataRow(Of llbEntityType As {EntityBase, New})(ByRef entity As llbEntityType, ByVal row As DataRow)
        For Each fld As IEntityField In entity.Fields
            entity.SetNewFieldValue(fld.Name, row.Item(fld.SourceColumnName))
        Next
        entity.IsNew = (row.RowState = DataRowState.Added)
    End Sub

So, even though this code is not used, its existence in the webservice class causes my previous failure. Marking it as Private also clears up the issue. So I think this is a peculiarity of web services in .Net, but I'd sure like to know what's happening, and idea??

This looks similar: http://blogs.msdn.com/mayankag/archive/2008/07/29/unable-to-generate-a-temporary-class-cs2009.aspx

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 22-Oct-2008 11:27:22   

This looks similar: http://blogs.msdn.com/mayankag/archive/2008/07/29/unable-to-generate-a-temporary-class-cs2009.aspx

The link in not working.

Which LLBLGen Pro runtime library version are you using?

Do you by any chance return or accept an Entity in any webMethod?

You are using SelfServicing while it's recommended to use Adapter in distributed scenarioes.

trevorg
User
Posts: 104
Joined: 15-Nov-2007
# Posted on: 22-Oct-2008 16:31:40   

Hmm, the link works for me.

Well I think it is some sort of a "bug" in the .Net platform itself...the link discusses an error that can occur in the webservice proxy that is generated at runtime for the consuming webform.

Anyways, I have just removed the code so it is no longer causing me a problem, I just thought Frans might know what the issue is just by looking at the error.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 22-Oct-2008 18:58:16   

Strange issue, especially because your API has no public types which are in the runtime lib, so the temp classes are not referring to types in the ormsupportclasses... (webservices generate temp code in C# which does the XML reading/writing, so if the webmethod has a type T in a method signature, these generated methods do too).

So concluding: no I don't know what causes this and I've not seen it before. As you're using .NET 3.5, perhaps using WCF will help?

Frans Bouma | Lead developer LLBLGen Pro